From: stigge@antcom.de (Roland Stigge)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RFC 02/15 v5] gpio: Add sysfs support to block GPIO API
Date: Thu, 18 Oct 2012 12:07:39 +0200 [thread overview]
Message-ID: <507FD4EB.1080204@antcom.de> (raw)
In-Reply-To: <20121017190520.GC25996@kroah.com>
On 10/17/2012 09:05 PM, Greg KH wrote:
>> +static int gpio_block_value_unexport(struct gpio_block *block)
>> +{
>> + struct device *dev;
>> + int i;
>> +
>> + dev = class_find_device(&gpio_block_class, NULL, block, match_export);
>> + if (!dev)
>> + return -ENODEV;
>> +
>> + for (i = 0; i < block->ngpio; i++)
>> + gpio_free(block->gpio[i]);
>> +
>> + device_remove_file(dev, &dev_attr_block_value);
>> +
>> + return 0;
>> +}
>
> Wait, what? You are removing a sysfs file in this function, from within
> a sysfs write:
Yes, exactly:
>> +static ssize_t gpio_block_exported_store(struct device *dev,
>> + struct device_attribute *attr,
>> + const char *buf, size_t size)
>> +{
>> + long value;
>> + int status;
>> + struct gpio_block *block = dev_get_drvdata(dev);
>> + int exported = gpio_block_value_is_exported(block);
>> +
>> + status = kstrtoul(buf, 0, &value);
>> + if (status < 0)
>> + goto err;
>> +
>> + if (value != exported) {
>> + if (value)
>> + status = gpio_block_value_export(block);
>> + else
>> + status = gpio_block_value_unexport(block);
>
> That looks like a recipie for disaster. Why do you allow userspace to
> do this?
Exporting for gpio blocks is done as follows: writing "1" to the
"exported" _device_ attribute of the gpio block creates the "values"
attribute and at the same time requests the whole block (including all
of its gpios) as "sysfs".
This admittedly deviates from the exporting of gpios (with the "export"
and "unexport" _class_ attributes) because blocks are not numbered. In
contrast, they are registered in a list (as was requested). Now, I
already had the idea of also having an "export" and "unexport" _class_
attribute for blocks also, but from a userspace perspective you only see
the presence and name of the gpio block if it is already being in sysfs
(even if not exported yet). If it wouldn't be this way, a user couldn't
guess how the required gpio block is called (or numbered), wouldn't even
know about its presence.
Just for understanding your strong desire for the device attribute
("value") being always present (in contrast to being created and removed
dynamically) - can you please give me any hint how the dynamic approach
would lead to disaster?
One possibility would be to always have "value" as a default device
attribute, but then it wouldn't be so obvious that it's useless until
"exported" is "1".
What do you think?
For now, I would elaborate about my terse "only available if /exported
is 1" like this:
"
Block GPIO devices are visible in sysfs as soon as they are registered
(e.g. via devicetree definition). For actual I/O use, their "exported"
boolean attribute must be set to "1". Then, the attribute "values" is
created and at the same time, the GPIOs in the block are requested for
exclusive use by sysfs.
"
Thanks in advance,
Roland
next prev parent reply other threads:[~2012-10-18 10:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-17 12:31 [PATCH RFC 00/15 v5] gpio: Add block GPIO Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 01/15 v5] gpio: Add a block GPIO API to gpiolib Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 02/15 v5] gpio: Add sysfs support to block GPIO API Roland Stigge
2012-10-17 19:05 ` Greg KH
2012-10-18 10:07 ` Roland Stigge [this message]
2012-10-19 10:35 ` Linus Walleij
2012-10-19 11:51 ` Roland Stigge
2012-10-22 8:55 ` Linus Walleij
2012-10-22 9:05 ` Roland Stigge
2012-10-19 18:02 ` Greg KH
2012-10-22 8:54 ` Linus Walleij
2012-10-17 12:31 ` [PATCH RFC 03/15 v5] gpiolib: Fix default attributes for class Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 04/15 v5] gpio: Add device tree support to block GPIO API Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 05/15 v5] gpio-max730x: Add " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 06/15 v5] gpio-lpc32xx: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 07/15 v5] gpio-generic: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 08/15 v5] gpio-pca953x: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 09/15 v5] gpio-em: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 10/15 v5] gpio-pl061: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 11/15 v5] gpio-max732x: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 12/15 v5] gpio-pcf857x: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 13/15 v5] gpio-xilinx: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 14/15 v5] gpio-vt8500: " Roland Stigge
2012-10-17 12:31 ` [PATCH RFC 15/15 v5] gpio-ucb1400: " Roland Stigge
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=507FD4EB.1080204@antcom.de \
--to=stigge@antcom.de \
--cc=linux-arm-kernel@lists.infradead.org \
/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).