diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2014-11-26 20:55:16 +0300 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-12-12 15:28:33 +0300 |
commit | 8d92db2827b68206f6930e79132243416183e083 (patch) | |
tree | 87306f1100237e03eab910b49800ac40c36b6916 /drivers/iio | |
parent | 08e7e0adaa17205f86894157d86c4bee3c714330 (diff) | |
download | linux-8d92db2827b68206f6930e79132243416183e083.tar.xz |
iio: buffer: Make length attribute read only for buffers without set_length
If a buffer implementation does not implement the set_length() callback the
length will be static and can not be changed by userspace. Mark the length
attribute as a read only property in this case so userspace is aware of this
rather than just silently accepting any length value.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/industrialio-buffer.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index ba89357fc096..4ca4c0a09923 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -418,8 +418,7 @@ static ssize_t iio_buffer_write_length(struct device *dev, if (iio_buffer_is_active(indio_dev->buffer)) { ret = -EBUSY; } else { - if (buffer->access->set_length) - buffer->access->set_length(buffer, val); + buffer->access->set_length(buffer, val); ret = 0; } mutex_unlock(&indio_dev->mlock); @@ -760,6 +759,8 @@ static const char * const iio_scan_elements_group_name = "scan_elements"; static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length, iio_buffer_write_length); +static struct device_attribute dev_attr_length_ro = __ATTR(length, + S_IRUGO, iio_buffer_read_length, NULL); static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); @@ -786,7 +787,10 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) if (!buffer->buffer_group.attrs) return -ENOMEM; - buffer->buffer_group.attrs[0] = &dev_attr_length.attr; + if (buffer->access->set_length) + buffer->buffer_group.attrs[0] = &dev_attr_length.attr; + else + buffer->buffer_group.attrs[0] = &dev_attr_length_ro.attr; buffer->buffer_group.attrs[1] = &dev_attr_enable.attr; if (buffer->attrs) memcpy(&buffer->buffer_group.attrs[2], buffer->attrs, |