diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2011-12-19 09:23:44 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-12-22 16:38:07 -0500 |
commit | e38c79e0825b673d97cecfb36bae9e859e724f1b (patch) | |
tree | dd36c49256e390391012c5185ace25ffe2aaa374 /drivers | |
parent | 5fd6218ca5928e4b59eb8a496aa1428fae1fb0d6 (diff) |
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')
-rw-r--r-- | drivers/staging/iio/industrialio-buffer.c | 17 |
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, | |||
396 | if (val == buffer->access->get_length(buffer)) | 396 | if (val == buffer->access->get_length(buffer)) |
397 | return len; | 397 | return len; |
398 | 398 | ||
399 | if (buffer->access->set_length) { | 399 | mutex_lock(&indio_dev->mlock); |
400 | buffer->access->set_length(buffer, val); | 400 | if (iio_buffer_enabled(indio_dev)) { |
401 | if (buffer->access->mark_param_change) | 401 | ret = -EBUSY; |
402 | buffer->access->mark_param_change(buffer); | 402 | } else { |
403 | if (buffer->access->set_length) { | ||
404 | buffer->access->set_length(buffer, val); | ||
405 | if (buffer->access->mark_param_change) | ||
406 | buffer->access->mark_param_change(buffer); | ||
407 | } | ||
408 | ret = 0; | ||
403 | } | 409 | } |
410 | mutex_unlock(&indio_dev->mlock); | ||
404 | 411 | ||
405 | return len; | 412 | return ret ? ret : len; |
406 | } | 413 | } |
407 | EXPORT_SYMBOL(iio_buffer_write_length); | 414 | EXPORT_SYMBOL(iio_buffer_write_length); |
408 | 415 | ||