]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: at91: simplify with cleanup.h
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Fri, 5 Jul 2024 10:40:46 +0000 (12:40 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 29 Jul 2024 19:31:11 +0000 (20:31 +0100)
Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240705-cleanup-h-iio-v1-3-77114c7e84c5@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/at91_adc.c

index af4b0224076f364cf3c1f331f4adee8053c59e19..510e826014e69b26e9b94f6e162ec66c54de86ed 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <linux/bitmap.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
@@ -541,22 +542,18 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
        int i;
 
        for (i = 0; i < st->caps->trigger_number; i++) {
-               char *name = kasprintf(GFP_KERNEL,
-                               "%s-dev%d-%s",
-                               idev->name,
-                               iio_device_id(idev),
-                               triggers[i].name);
+               char *name __free(kfree) = kasprintf(GFP_KERNEL, "%s-dev%d-%s",
+                                                    idev->name,
+                                                    iio_device_id(idev),
+                                                    triggers[i].name);
                if (!name)
                        return -ENOMEM;
 
                if (strcmp(trigger_name, name) == 0) {
-                       kfree(name);
                        if (triggers[i].value == 0)
                                return -EINVAL;
                        return triggers[i].value;
                }
-
-               kfree(name);
        }
 
        return -EINVAL;