Message ID | 1439561466-14350-8-git-send-email-mpa@pengutronix.de |
---|---|
State | New |
Headers | show |
On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote:
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
This has too terse commit description. I don't understand the patch or
what it is supposed to do.
Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Sep 21, 2015 at 06:09:15PM -0700, Linus Walleij wrote: > On Fri, Aug 14, 2015 at 7:11 AM, Markus Pargmann <mpa@pengutronix.de> wrote: > > > Signed-off-by: Markus Pargmann <mpa@pengutronix.de> > > This has too terse commit description. I don't understand the patch or > what it is supposed to do. Sorry, indeed, this requires a commit description. I would add something like this: In '/sys/class/gpio/' GPIOs can be exported by using their GPIO number. If the exported GPIO has a name, it will show up as a new directory in '/sys/class/gpio/<GPIO_NAME>'. It is somehow inconsistent to use a number for exporting and the name for accessing the GPIO. This patch adds the possibility to use the GPIO name to export it. This introduces a consistent behaviour for exporting and accessing a GPIO from userspace. The mechanism of parsing the GPIO name is a fallback mechanism. This ensures backwards compatibility of the gpio interface. If the string passed to '/sys/class/gpio/export' can not be parsed as number, it tries to match a GPIO name. The same behaviour is implemented for the 'unexport' file. The implementation uses the previously defined gpio_name_to_desc(). Thanks, Markus
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 2022cfb00aeb..e401878d05ce 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -455,18 +455,28 @@ static ssize_t export_store(struct class *class, const char *buf, size_t len) { long gpio; - struct gpio_desc *desc; + struct gpio_desc *desc = NULL; int status; status = kstrtol(buf, 0, &gpio); - if (status < 0) - goto done; + if (!status) + desc = gpio_to_desc(gpio); - desc = gpio_to_desc(gpio); - /* reject invalid GPIOs */ + /* Fall back on detection by name */ if (!desc) { - pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); - return -EINVAL; + char *gpio_name = kstrdup(buf, GFP_KERNEL); + + if (!gpio_name) + return -ENOMEM; + + desc = gpio_name_to_desc(strim(gpio_name)); + kfree(gpio_name); + + /* reject invalid GPIOs */ + if (!desc) { + pr_warn("%s: invalid GPIO %s\n", __func__, buf); + return -EINVAL; + } } /* No extra locking here; FLAG_SYSFS just signifies that the @@ -497,17 +507,28 @@ static ssize_t unexport_store(struct class *class, const char *buf, size_t len) { long gpio; - struct gpio_desc *desc; + struct gpio_desc *desc = NULL; int status; status = kstrtol(buf, 0, &gpio); - if (status < 0) - goto done; + if (!status) + desc = gpio_to_desc(gpio); + + /* Fall back on detection by name */ + if (!desc) { + char *gpio_name = kstrdup(buf, GFP_KERNEL); + + if (!gpio_name) + return -ENOMEM; + + desc = gpio_name_to_desc(strim(gpio_name)); + kfree(gpio_name); + } + - desc = gpio_to_desc(gpio); /* reject bogus commands (gpio_unexport ignores them) */ if (!desc) { - pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); + pr_warn("%s: invalid GPIO %s\n", __func__, buf); return -EINVAL; } @@ -521,7 +542,7 @@ static ssize_t unexport_store(struct class *class, status = 0; gpiod_free(desc); } -done: + if (status) pr_debug("%s: status %d\n", __func__, status); return status ? : len;
Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- drivers/gpio/gpiolib-sysfs.c | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-)