Skip to content

Commit

Permalink
staging:iio: add caching of the number of bytes in a scan.
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed Apr 24, 2012
1 parent f126480 commit 420fe2e
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 28 deletions.
3 changes: 1 addition & 2 deletions drivers/staging/iio/accel/adis16201_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/iio/accel/adis16203_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/iio/accel/adis16204_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
struct iio_buffer *ring = indio_dev->buffer;
int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/iio/accel/adis16209_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct adis16209_state *st = iio_priv(indio_dev);
struct iio_buffer *ring = indio_dev->buffer;

int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize , GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/iio/accel/adis16240_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/iio/accel/lis3l02dq_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct iio_buffer *buffer = indio_dev->buffer;
int len = 0;
size_t datasize = buffer->access->get_bytes_per_datum(buffer);
char *data = kmalloc(datasize, GFP_KERNEL);
char *data;

data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(indio_dev->dev.parent,
"memory alloc failed in buffer bh");
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/iio/adc/ad7606_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
__u8 *buf;
int ret;

buf = kzalloc(ring->access->get_bytes_per_datum(ring),
GFP_KERNEL);
buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (buf == NULL)
return;

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/iio/gyro/adis16260_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
struct iio_buffer *ring = indio_dev->buffer;
int i = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize , GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
2 changes: 2 additions & 0 deletions drivers/staging/iio/iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ struct iio_buffer_setup_ops {
* and owner
* @event_interface: [INTERN] event chrdevs associated with interrupt lines
* @buffer: [DRIVER] any buffer present
* @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
* @mlock: [INTERN] lock used to prevent simultaneous device state
* changes
* @available_scan_masks: [DRIVER] optional array of allowed bitmasks
Expand Down Expand Up @@ -335,6 +336,7 @@ struct iio_dev {
struct iio_event_interface *event_interface;

struct iio_buffer *buffer;
int scan_bytes;
struct mutex mlock;

const unsigned long *available_scan_masks;
Expand Down
9 changes: 3 additions & 6 deletions drivers/staging/iio/iio_simple_dummy_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct iio_buffer *buffer = indio_dev->buffer;
int len = 0;
/*
* The datasize is obtained from the buffer. It was stored when
* the preenable setup function was called.
*/
size_t datasize = buffer->access->get_bytes_per_datum(buffer);
u16 *data = kmalloc(datasize, GFP_KERNEL);
u16 *data;

data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL)
return -ENOMEM;

Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/iio/imu/adis16400_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
struct iio_buffer *ring = indio_dev->buffer;
int i = 0, j, ret = 0;
s16 *data;
size_t datasize = ring->access->get_bytes_per_datum(ring);

/* Asumption that long is enough for maximum channels */
unsigned long mask = *indio_dev->active_scan_mask;
int scan_count = bitmap_weight(indio_dev->active_scan_mask,
indio_dev->masklength);
data = kmalloc(datasize , GFP_KERNEL);
data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return -ENOMEM;
Expand Down
6 changes: 3 additions & 3 deletions drivers/staging/iio/industrialio-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
{
struct iio_buffer *buffer = indio_dev->buffer;
unsigned bytes;
dev_dbg(&indio_dev->dev, "%s\n", __func__);

/* How much space will the demuxed element take? */
bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
indio_dev->scan_bytes =
iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
buffer->scan_timestamp);
buffer->access->set_bytes_per_datum(buffer, bytes);
buffer->access->set_bytes_per_datum(buffer, indio_dev->scan_bytes);

/* What scan mask do we actually have ?*/
if (indio_dev->available_scan_masks)
Expand Down

0 comments on commit 420fe2e

Please sign in to comment.