]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: st_sensors: drop temporary kmalloc buffer and reuse buffer_data
authorSanjay Chitroda <sanjayembeddedse@gmail.com>
Sun, 15 Mar 2026 12:16:25 +0000 (17:46 +0530)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 21 Mar 2026 20:09:55 +0000 (20:09 +0000)
Replace the per-call kmalloc() scratch buffer with the existing
buffer_data[] field present in struct st_sensor_data. The existing buffer
is DMA-aligned and sufficiently sized for all channel widths, so using it
avoids unnecessary dynamic memory allocation on each read.

This simplifies the code, removes redundant allocation and cleanup.
No functional change intended.

Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/common/st_sensors/st_sensors_core.c

index dac593be56958fd0be92e13f628350fcfd0f040d..dbc5e16fbde43ee61bdffeb94d7119a226f3949f 100644 (file)
@@ -501,14 +501,12 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
 
        byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
                                        ch->scan_type.shift, 8);
-       outdata = kmalloc(byte_for_channel, GFP_DMA | GFP_KERNEL);
-       if (!outdata)
-               return -ENOMEM;
+       outdata = sdata->buffer_data;
 
        err = regmap_bulk_read(sdata->regmap, ch->address,
                               outdata, byte_for_channel);
        if (err < 0)
-               goto st_sensors_free_memory;
+               return err;
 
        if (byte_for_channel == 1)
                *data = (s8)*outdata;
@@ -517,10 +515,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
        else if (byte_for_channel == 3)
                *data = (s32)sign_extend32(get_unaligned_le24(outdata), 23);
 
-st_sensors_free_memory:
-       kfree(outdata);
-
-       return err;
+       return 0;
 }
 
 int st_sensors_read_info_raw(struct iio_dev *indio_dev,