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: adc: max1363: Use a small fixed size buffer to replace dynamic allocation

Drop the recurrent allocation of the data buffer from the trigger
handler and put it in the iio_priv(). This way, the maximum amount of
channels is always allocated in favor of simpler code and drop
of usage of the internal private variable "scan_timestamp" of the
struct iio_dev.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://patch.msgid.link/20241214191421.94172-3-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Vasileios Amoiridis and committed by
Jonathan Cameron
45e3146d 6fcabe62

+9 -21
+9 -21
drivers/iio/adc/max1363.c
··· 161 161 * @vref_uv: Actual (external or internal) reference voltage 162 162 * @send: function used to send data to the chip 163 163 * @recv: function used to receive data from the chip 164 + * @data: buffer to store channel data and timestamp 164 165 */ 165 166 struct max1363_state { 166 167 struct i2c_client *client; ··· 187 186 const char *buf, int count); 188 187 int (*recv)(const struct i2c_client *client, 189 188 char *buf, int count); 189 + struct { 190 + u8 buf[MAX1363_MAX_CHANNELS * 2]; 191 + aligned_s64 ts; 192 + } data; 190 193 }; 191 194 192 195 #define MAX1363_MODE_SINGLE(_num, _mask) { \ ··· 1467 1462 struct iio_poll_func *pf = p; 1468 1463 struct iio_dev *indio_dev = pf->indio_dev; 1469 1464 struct max1363_state *st = iio_priv(indio_dev); 1470 - __u8 *rxbuf; 1471 1465 int b_sent; 1472 - size_t d_size; 1473 1466 unsigned long numvals = bitmap_weight(st->current_mode->modemask, 1474 1467 MAX1363_MAX_CHANNELS); 1475 1468 1476 - /* Ensure the timestamp is 8 byte aligned */ 1477 - if (st->chip_info->bits != 8) 1478 - d_size = numvals*2; 1479 - else 1480 - d_size = numvals; 1481 - if (indio_dev->scan_timestamp) { 1482 - d_size += sizeof(s64); 1483 - if (d_size % sizeof(s64)) 1484 - d_size += sizeof(s64) - (d_size % sizeof(s64)); 1485 - } 1486 1469 /* Monitor mode prevents reading. Whilst not currently implemented 1487 1470 * might as well have this test in here in the meantime as it does 1488 1471 * no harm. ··· 1478 1485 if (numvals == 0) 1479 1486 goto done; 1480 1487 1481 - rxbuf = kmalloc(d_size, GFP_KERNEL); 1482 - if (rxbuf == NULL) 1483 - goto done; 1484 1488 if (st->chip_info->bits != 8) 1485 - b_sent = st->recv(st->client, rxbuf, numvals * 2); 1489 + b_sent = st->recv(st->client, st->data.buf, numvals * 2); 1486 1490 else 1487 - b_sent = st->recv(st->client, rxbuf, numvals); 1491 + b_sent = st->recv(st->client, st->data.buf, numvals); 1488 1492 if (b_sent < 0) 1489 - goto done_free; 1493 + goto done; 1490 1494 1491 - iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, 1495 + iio_push_to_buffers_with_timestamp(indio_dev, &st->data, 1492 1496 iio_get_time_ns(indio_dev)); 1493 1497 1494 - done_free: 1495 - kfree(rxbuf); 1496 1498 done: 1497 1499 iio_trigger_notify_done(indio_dev->trig); 1498 1500