#include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 
 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;
 }