Skip to content

Commit

Permalink
staging:iio: Disallow modifying buffer size when buffer is enabled
Browse files Browse the repository at this point in the history
The buffer buffer storage is only update when enabling the buffer. Changing the
buffer size while the buffer is enabled will confuse the buffer in regard to
its actual buffer size and can cause potential memory corruption. Thus it is
only safe to modify the buffer size when the buffer is disabled.

Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Lars-Peter Clausen authored and Greg Kroah-Hartman committed Dec 22, 2011
1 parent 5fd6218 commit e38c79e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/staging/iio/industrialio-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,20 @@ ssize_t iio_buffer_write_length(struct device *dev,
if (val == buffer->access->get_length(buffer))
return len;

if (buffer->access->set_length) {
buffer->access->set_length(buffer, val);
if (buffer->access->mark_param_change)
buffer->access->mark_param_change(buffer);
mutex_lock(&indio_dev->mlock);
if (iio_buffer_enabled(indio_dev)) {
ret = -EBUSY;
} else {
if (buffer->access->set_length) {
buffer->access->set_length(buffer, val);
if (buffer->access->mark_param_change)
buffer->access->mark_param_change(buffer);
}
ret = 0;
}
mutex_unlock(&indio_dev->mlock);

return len;
return ret ? ret : len;
}
EXPORT_SYMBOL(iio_buffer_write_length);

Expand Down

0 comments on commit e38c79e

Please sign in to comment.