linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Kent Gibson <warthog618@gmail.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH v1 2/2] gpiolib: Introduce gpiod_request_user() helper
Date: Tue, 18 May 2021 18:50:13 +0300	[thread overview]
Message-ID: <20210518155013.45622-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210518155013.45622-1-andriy.shevchenko@linux.intel.com>

The gpiod_request_user() is a special helper to avoid propagating stuff
to user space that should not be propagated, e.g. internal error codes.

For now, hide EPROBE_DEFER with ENODEV.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-cdev.c  | 21 ++++++---------------
 drivers/gpio/gpiolib-sysfs.c |  7 ++-----
 drivers/gpio/gpiolib.h       | 12 ++++++++++++
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 1d8f66880d63..8a934914f93a 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -330,12 +330,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 			goto out_free_lh;
 		}
 
-		ret = gpiod_request(desc, lh->label);
-		if (ret) {
-			if (ret == -EPROBE_DEFER)
-				ret = -ENODEV;
+		ret = gpiod_request_user(desc, lh->label);
+		if (ret)
 			goto out_free_lh;
-		}
 		lh->descs[i] = desc;
 		linehandle_flags_to_desc_flags(handlereq.flags, &desc->flags);
 
@@ -1381,12 +1378,9 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
 			goto out_free_linereq;
 		}
 
-		ret = gpiod_request(desc, lr->label);
-		if (ret) {
-			if (ret == -EPROBE_DEFER)
-				ret = -ENODEV;
+		ret = gpiod_request_user(desc, lr->label);
+		if (ret)
 			goto out_free_linereq;
-		}
 
 		lr->lines[i].desc = desc;
 		flags = gpio_v2_line_config_flags(lc, i);
@@ -1770,12 +1764,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 		}
 	}
 
-	ret = gpiod_request(desc, le->label);
-	if (ret) {
-		if (ret == -EPROBE_DEFER)
-			ret = -ENODEV;
+	ret = gpiod_request_user(desc, le->label);
+	if (ret)
 		goto out_free_le;
-	}
 	le->desc = desc;
 	le->eflags = eflags;
 
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index d836aba91d3c..22a9ad1a2978 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -473,12 +473,9 @@ static ssize_t export_store(struct class *class,
 	 * they may be undone on its behalf too.
 	 */
 
-	status = gpiod_request(desc, "sysfs");
-	if (status) {
-		if (status == -EPROBE_DEFER)
-			status = -ENODEV;
+	status = gpiod_request_user(desc, "sysfs");
+	if (status)
 		goto done;
-	}
 
 	status = gpiod_set_transitory(desc, false);
 	if (!status) {
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 69c96a4276de..7f760745c457 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -142,6 +142,18 @@ struct gpio_desc {
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
 void gpiod_free(struct gpio_desc *desc);
+
+static inline int gpiod_request_user(struct gpio_desc *desc, const char *label)
+{
+	int ret;
+
+	ret = gpiod_request(desc, label);
+	if (ret == -EPROBE_DEFER)
+		ret = -ENODEV;
+
+	return ret;
+}
+
 int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
 		unsigned long lflags, enum gpiod_flags dflags);
 int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);
-- 
2.30.2


  reply	other threads:[~2021-05-18 15:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 15:50 [PATCH v1 1/2] gpiolib: Never return internal error codes to user space Andy Shevchenko
2021-05-18 15:50 ` Andy Shevchenko [this message]
2021-05-25  0:27   ` [PATCH v1 2/2] gpiolib: Introduce gpiod_request_user() helper Linus Walleij
2021-05-18 23:24 ` [PATCH v1 1/2] gpiolib: Never return internal error codes to user space Kent Gibson
2021-05-19  7:45   ` Andy Shevchenko
2021-05-19  8:04     ` Kent Gibson
2021-05-19  8:30       ` Andy Shevchenko
2021-05-20 13:02         ` Bartosz Golaszewski
2021-05-20 13:14           ` Andy Shevchenko
2021-05-20 14:39             ` Bartosz Golaszewski
2021-11-23 19:15               ` Andy Shevchenko
2021-11-24 12:46                 ` Bartosz Golaszewski

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=20210518155013.45622-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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).