diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-03-26 18:43:00 +0000 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-03-29 09:16:47 +0000 |
commit | d8dca33027c1fda3318fe8af85456b801ef88e1e (patch) | |
tree | 470c0d2b64075ccb2cf57fd1e8cfd16e69f28ced /drivers/staging/iio/adc/ad799x_core.c | |
parent | d00698df2180ecd78b2892856b310dfedd5f6fe7 (diff) |
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_core.c')
-rw-r--r-- | drivers/staging/iio/adc/ad799x_core.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index b7510557d064..8dc97b36e05a 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -104,6 +104,13 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev, { struct ad799x_state *st = iio_priv(indio_dev); + kfree(st->rx_buf); + st->rx_buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + if (!st->rx_buf) + return -ENOMEM; + + st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2; + switch (st->id) { case ad7997: case ad7998: @@ -665,6 +672,7 @@ static int ad799x_remove(struct i2c_client *client) regulator_disable(st->reg); regulator_put(st->reg); } + kfree(st->rx_buf); iio_device_free(indio_dev); return 0; |