Skip to content

Commit

Permalink
iio: buffer: Fix NULL pointer deref caused by empty scan mask
Browse files Browse the repository at this point in the history
iio_scan_mask_match() returns NULL if the passed in scan mask is empty. This
will happen if no channel has been selected and buffer is enabled.
iio_sw_buffer_preenable() will assign NULL to indio_dev->active_scan_mask in
this case. As a result iio_update_demux() will cause a NULL pointer deref,
because it expects active_scan_mask to be non-NULL.

Since it does not make much sense to start data capture if there is no data to
capture this patch updates the code to fail gracefully in iio_scan_mask_match()
instead of crashing the kernel.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Lars-Peter Clausen authored and Greg Kroah-Hartman committed Jun 15, 2012
1 parent fb1c4bc commit aff1eb4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/iio/industrialio-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
buffer->scan_mask);
else
indio_dev->active_scan_mask = buffer->scan_mask;

if (indio_dev->active_scan_mask == NULL)
return -EINVAL;

iio_update_demux(indio_dev);

if (indio_dev->info->update_scan_mode)
Expand Down

0 comments on commit aff1eb4

Please sign in to comment.