]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: accel: bma400: simplify with cleanup.h
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Fri, 5 Jul 2024 10:40:44 +0000 (12:40 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 29 Jul 2024 19:31:10 +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-1-77114c7e84c5@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bma400_core.c

index e90e2f01550ad375b5b0e781982b3ecbf595dce8..89db242f06e0bed46a54f24390073addda63a7ce 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -795,21 +796,19 @@ static int bma400_enable_steps(struct bma400_data *data, int val)
 
 static int bma400_get_steps_reg(struct bma400_data *data, int *val)
 {
-       u8 *steps_raw;
        int ret;
 
-       steps_raw = kmalloc(BMA400_STEP_RAW_LEN, GFP_KERNEL);
+       u8 *steps_raw __free(kfree) = kmalloc(BMA400_STEP_RAW_LEN, GFP_KERNEL);
        if (!steps_raw)
                return -ENOMEM;
 
        ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
                               steps_raw, BMA400_STEP_RAW_LEN);
-       if (ret) {
-               kfree(steps_raw);
+       if (ret)
                return ret;
-       }
+
        *val = get_unaligned_le24(steps_raw);
-       kfree(steps_raw);
+
        return IIO_VAL_INT;
 }