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

Configure Feed

Select the types of activity you want to include in your feed.

iio: st_sensors: drop temporary kmalloc buffer and reuse buffer_data

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>

authored by

Sanjay Chitroda and committed by
Jonathan Cameron
1ac30f58 733bcf18

+3 -8
+3 -8
drivers/iio/common/st_sensors/st_sensors_core.c
··· 501 501 502 502 byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits + 503 503 ch->scan_type.shift, 8); 504 - outdata = kmalloc(byte_for_channel, GFP_DMA | GFP_KERNEL); 505 - if (!outdata) 506 - return -ENOMEM; 504 + outdata = sdata->buffer_data; 507 505 508 506 err = regmap_bulk_read(sdata->regmap, ch->address, 509 507 outdata, byte_for_channel); 510 508 if (err < 0) 511 - goto st_sensors_free_memory; 509 + return err; 512 510 513 511 if (byte_for_channel == 1) 514 512 *data = (s8)*outdata; ··· 515 517 else if (byte_for_channel == 3) 516 518 *data = (s32)sign_extend32(get_unaligned_le24(outdata), 23); 517 519 518 - st_sensors_free_memory: 519 - kfree(outdata); 520 - 521 - return err; 520 + return 0; 522 521 } 523 522 524 523 int st_sensors_read_info_raw(struct iio_dev *indio_dev,