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>
This commit is contained in:
parent
d00698df21
commit
d8dca33027
@ -106,6 +106,9 @@ struct ad799x_state {
|
|||||||
u16 int_vref_mv;
|
u16 int_vref_mv;
|
||||||
unsigned id;
|
unsigned id;
|
||||||
u16 config;
|
u16 config;
|
||||||
|
|
||||||
|
u8 *rx_buf;
|
||||||
|
unsigned int transfer_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -104,6 +104,13 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
struct ad799x_state *st = iio_priv(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) {
|
switch (st->id) {
|
||||||
case ad7997:
|
case ad7997:
|
||||||
case ad7998:
|
case ad7998:
|
||||||
@ -665,6 +672,7 @@ static int ad799x_remove(struct i2c_client *client)
|
|||||||
regulator_disable(st->reg);
|
regulator_disable(st->reg);
|
||||||
regulator_put(st->reg);
|
regulator_put(st->reg);
|
||||||
}
|
}
|
||||||
|
kfree(st->rx_buf);
|
||||||
iio_device_free(indio_dev);
|
iio_device_free(indio_dev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,14 +36,9 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
|
|||||||
struct iio_dev *indio_dev = pf->indio_dev;
|
struct iio_dev *indio_dev = pf->indio_dev;
|
||||||
struct ad799x_state *st = iio_priv(indio_dev);
|
struct ad799x_state *st = iio_priv(indio_dev);
|
||||||
s64 time_ns;
|
s64 time_ns;
|
||||||
__u8 *rxbuf;
|
|
||||||
int b_sent;
|
int b_sent;
|
||||||
u8 cmd;
|
u8 cmd;
|
||||||
|
|
||||||
rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
|
|
||||||
if (rxbuf == NULL)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
switch (st->id) {
|
switch (st->id) {
|
||||||
case ad7991:
|
case ad7991:
|
||||||
case ad7995:
|
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,
|
b_sent = i2c_smbus_read_i2c_block_data(st->client,
|
||||||
cmd, bitmap_weight(indio_dev->active_scan_mask,
|
cmd, st->transfer_size, st->rx_buf);
|
||||||
indio_dev->masklength) * 2, rxbuf);
|
|
||||||
if (b_sent < 0)
|
if (b_sent < 0)
|
||||||
goto done;
|
goto out;
|
||||||
|
|
||||||
time_ns = iio_get_time_ns();
|
time_ns = iio_get_time_ns();
|
||||||
|
|
||||||
if (indio_dev->scan_timestamp)
|
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));
|
&time_ns, sizeof(time_ns));
|
||||||
|
|
||||||
iio_push_to_buffers(indio_dev, rxbuf);
|
iio_push_to_buffers(indio_dev, st->rx_buf);
|
||||||
done:
|
|
||||||
kfree(rxbuf);
|
|
||||||
out:
|
out:
|
||||||
iio_trigger_notify_done(indio_dev->trig);
|
iio_trigger_notify_done(indio_dev->trig);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user