Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: accel: bma400: Fix memory leak in bma400_get_steps_reg()

When regmap_bulk_read() fails, it does not free steps_raw,
which will cause a memory leak issue, this patch fixes it.

Fixes: d221de60eee3 ("iio: accel: bma400: Add separate channel for step counter")
Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
Reviewed-by: Jagath Jog J <jagathjog1996@gmail.com>
Link: https://lore.kernel.org/r/20221110010726.235601-1-dongchenchen2@huawei.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Dong Chenchen and committed by
Jonathan Cameron
20690cd5 6ac12303

+3 -1
+3 -1
drivers/iio/accel/bma400_core.c
··· 805 805 806 806 ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG, 807 807 steps_raw, BMA400_STEP_RAW_LEN); 808 - if (ret) 808 + if (ret) { 809 + kfree(steps_raw); 809 810 return ret; 811 + } 810 812 *val = get_unaligned_le24(steps_raw); 811 813 kfree(steps_raw); 812 814 return IIO_VAL_INT;