summaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2011-12-19 15:23:44 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-22 13:38:07 -0800
commite38c79e0825b673d97cecfb36bae9e859e724f1b (patch)
treedd36c49256e390391012c5185ace25ffe2aaa374 /drivers/staging
parent5fd6218ca5928e4b59eb8a496aa1428fae1fb0d6 (diff)
downloadblackbird-op-linux-e38c79e0825b673d97cecfb36bae9e859e724f1b.tar.gz
blackbird-op-linux-e38c79e0825b673d97cecfb36bae9e859e724f1b.zip
staging:iio: Disallow modifying buffer size when buffer is enabled
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>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/iio/industrialio-buffer.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 747b9013a666..59472890cb2a 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -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);
OpenPOWER on IntegriCloud