diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-03-26 18:43:00 (GMT) |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-03-29 09:16:47 (GMT) |
commit | d8dca33027c1fda3318fe8af85456b801ef88e1e (patch) | |
tree | 470c0d2b64075ccb2cf57fd1e8cfd16e69f28ced /drivers/staging/iio/adc/ad799x_ring.c | |
parent | d00698df2180ecd78b2892856b310dfedd5f6fe7 (diff) | |
download | linux-fsl-qoriq-d8dca33027c1fda3318fe8af85456b801ef88e1e.tar.xz |
staging:iio:ad799x: Preallocate sample buffer
Avoid allocating and freeing the sample buffer for each transfer. Instead
allocate it once when we start sampling. Also pre-compute the number of bytes we
need to transfer in the same way.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio/adc/ad799x_ring.c')
-rw-r--r-- | drivers/staging/iio/adc/ad799x_ring.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c index 2c5f384..c2ebae1 100644 --- a/drivers/staging/iio/adc/ad799x_ring.c +++ b/drivers/staging/iio/adc/ad799x_ring.c @@ -36,14 +36,9 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct ad799x_state *st = iio_priv(indio_dev); s64 time_ns; - __u8 *rxbuf; int b_sent; u8 cmd; - rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); - if (rxbuf == NULL) - goto out; - switch (st->id) { case ad7991: case ad7995: @@ -66,20 +61,17 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) } b_sent = i2c_smbus_read_i2c_block_data(st->client, - cmd, bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength) * 2, rxbuf); + cmd, st->transfer_size, st->rx_buf); if (b_sent < 0) - goto done; + goto out; time_ns = iio_get_time_ns(); if (indio_dev->scan_timestamp) - memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64), + memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64), &time_ns, sizeof(time_ns)); - iio_push_to_buffers(indio_dev, rxbuf); -done: - kfree(rxbuf); + iio_push_to_buffers(indio_dev, st->rx_buf); out: iio_trigger_notify_done(indio_dev->trig); |