From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Peter Meerwald <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 10/11] iio: buffer: Make length attribute read only for buffers without set_length
Date: Wed, 26 Nov 2014 18:55:16 +0100 [thread overview]
Message-ID: <1417024517-7564-11-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1417024517-7564-1-git-send-email-lars@metafoo.de>
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>
---
drivers/iio/industrialio-buffer.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index a4d3ff6..3e0c3a9 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -416,8 +416,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);
@@ -755,6 +754,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);
@@ -781,7 +782,10 @@ int iio_buffer_alloc_sysfs(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,
--
1.8.0
next prev parent reply other threads:[~2014-11-26 17:55 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 17:55 [PATCH 00/11] iio: Buffer cleanups and consolidations Lars-Peter Clausen
2014-11-26 17:55 ` [PATCH 01/11] staging:iio:ad5933: Don't enable channels by default Lars-Peter Clausen
2014-12-04 22:51 ` Daniel Baluta
2014-12-12 10:21 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 02/11] staging:iio:sca3000: " Lars-Peter Clausen
2014-12-04 22:51 ` Daniel Baluta
2014-12-12 10:22 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 03/11] iio: Unexport iio_scan_mask_set() Lars-Peter Clausen
2014-12-05 9:53 ` Daniel Baluta
2014-12-12 10:23 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 04/11] staging:iio:sca3000: Register same channels for device and buffer Lars-Peter Clausen
2014-12-04 22:56 ` Daniel Baluta
2014-12-12 10:28 ` Jonathan Cameron
2014-12-10 22:35 ` Hartmut Knaack
2014-12-12 10:29 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 05/11] staging:iio:dummy: " Lars-Peter Clausen
2014-12-04 14:27 ` Daniel Baluta
2014-12-12 10:30 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 06/11] iio: Move buffer registration to the core Lars-Peter Clausen
2014-12-04 14:23 ` Daniel Baluta
2014-12-12 10:49 ` Jonathan Cameron
2014-12-12 10:48 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 07/11] iio: Remove get_bytes_per_datum() from iio_buffer_access_funcs Lars-Peter Clausen
2014-12-12 10:51 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 08/11] iio: buffer: Move iio_buffer_alloc_sysfs and iio_buffer_free_sysfs Lars-Peter Clausen
2014-12-12 10:57 ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 09/11] iio: buffer: Allocate standard attributes in the core Lars-Peter Clausen
2014-12-10 22:42 ` Hartmut Knaack
2014-12-12 11:06 ` Jonathan Cameron
2014-11-26 17:55 ` Lars-Peter Clausen [this message]
2014-12-12 11:08 ` [PATCH 10/11] iio: buffer: Make length attribute read only for buffers without set_length Jonathan Cameron
2014-12-12 11:11 ` Jonathan Cameron
2014-12-18 16:35 ` Lars-Peter Clausen
2014-11-26 17:55 ` [PATCH 11/11] iio: buffer: Drop get_length callback Lars-Peter Clausen
2014-12-12 11:13 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1417024517-7564-11-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).