From patchwork Tue Aug 4 09:23:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Pargmann X-Patchwork-Id: 503436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3C4B81402C8 for ; Tue, 4 Aug 2015 19:23:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932416AbbHDJXj (ORCPT ); Tue, 4 Aug 2015 05:23:39 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:40314 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932399AbbHDJXi (ORCPT ); Tue, 4 Aug 2015 05:23:38 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ZMWaU-0007NA-Au; Tue, 04 Aug 2015 09:24:38 +0200 Received: from mpa by dude.hi.pengutronix.de with local (Exim 4.86_RC4) (envelope-from ) id 1ZMYRZ-0007MB-Kb; Tue, 04 Aug 2015 11:23:33 +0200 From: Markus Pargmann To: Linus Walleij Cc: Alexandre Courbot , Arun Bharadwaj , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Johan Hovold , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Markus Pargmann Subject: [PATCH 4/6] gpiolib-sysfs: Add gpio name parsing for sysfs export Date: Tue, 4 Aug 2015 11:23:21 +0200 Message-Id: <1438680203-13432-5-git-send-email-mpa@pengutronix.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438680203-13432-1-git-send-email-mpa@pengutronix.de> References: <1438680203-13432-1-git-send-email-mpa@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Signed-off-by: Markus Pargmann --- drivers/gpio/gpiolib-sysfs.c | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index b57ed8e55ab5..e22a86e31c90 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -443,18 +443,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 @@ -485,17 +495,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; } @@ -509,7 +530,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;