From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Kent Gibson <warthog618@gmail.com>, Alex Elder <elder@linaro.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
"Paul E . McKenney" <paulmck@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Wolfram Sang <wsa@the-dreams.de>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH 18/22] gpio: add the can_sleep flag to struct gpio_device
Date: Tue, 30 Jan 2024 13:48:24 +0100 [thread overview]
Message-ID: <20240130124828.14678-19-brgl@bgdev.pl> (raw)
In-Reply-To: <20240130124828.14678-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Duplicating the can_sleep value in GPIO device will allow us to not
needlessly dereference the chip pointer in several places and reduce the
number of SRCU read-only critical sections.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpiolib.c | 11 ++++++-----
drivers/gpio/gpiolib.h | 3 +++
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e6b9f1c82a7d..9548c9e53197 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -893,6 +893,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
}
gdev->ngpio = gc->ngpio;
+ gdev->can_sleep = gc->can_sleep;
scoped_guard(mutex, &gpio_devices_lock) {
/*
@@ -3063,7 +3064,7 @@ int gpiod_get_raw_value(const struct gpio_desc *desc)
{
VALIDATE_DESC(desc);
/* Should be using gpiod_get_raw_value_cansleep() */
- WARN_ON(desc->gdev->chip->can_sleep);
+ WARN_ON(desc->gdev->can_sleep);
return gpiod_get_raw_value_commit(desc);
}
EXPORT_SYMBOL_GPL(gpiod_get_raw_value);
@@ -3084,7 +3085,7 @@ int gpiod_get_value(const struct gpio_desc *desc)
VALIDATE_DESC(desc);
/* Should be using gpiod_get_value_cansleep() */
- WARN_ON(desc->gdev->chip->can_sleep);
+ WARN_ON(desc->gdev->can_sleep);
value = gpiod_get_raw_value_commit(desc);
if (value < 0)
@@ -3357,7 +3358,7 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int value)
{
VALIDATE_DESC_VOID(desc);
/* Should be using gpiod_set_raw_value_cansleep() */
- WARN_ON(desc->gdev->chip->can_sleep);
+ WARN_ON(desc->gdev->can_sleep);
gpiod_set_raw_value_commit(desc, value);
}
EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
@@ -3398,7 +3399,7 @@ void gpiod_set_value(struct gpio_desc *desc, int value)
{
VALIDATE_DESC_VOID(desc);
/* Should be using gpiod_set_value_cansleep() */
- WARN_ON(desc->gdev->chip->can_sleep);
+ WARN_ON(desc->gdev->can_sleep);
gpiod_set_value_nocheck(desc, value);
}
EXPORT_SYMBOL_GPL(gpiod_set_value);
@@ -3462,7 +3463,7 @@ EXPORT_SYMBOL_GPL(gpiod_set_array_value);
int gpiod_cansleep(const struct gpio_desc *desc)
{
VALIDATE_DESC(desc);
- return desc->gdev->chip->can_sleep;
+ return desc->gdev->can_sleep;
}
EXPORT_SYMBOL_GPL(gpiod_cansleep);
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 9b7afe87f1bd..43ff4931e2c3 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -34,6 +34,8 @@
* @descs: array of ngpio descriptors.
* @ngpio: the number of GPIO lines on this GPIO device, equal to the size
* of the @descs array.
+ * @can_sleep: indicate whether the GPIO chip driver's callbacks can sleep
+ * implying that they cannot be used from atomic context
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
* at device creation time.
* @label: a descriptive name for the GPIO device, such as the part number
@@ -64,6 +66,7 @@ struct gpio_device {
struct gpio_desc *descs;
int base;
u16 ngpio;
+ bool can_sleep;
const char *label;
void *data;
struct list_head list;
--
2.40.1
next prev parent reply other threads:[~2024-01-30 12:48 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 12:48 [PATCH 00/22] gpio: rework locking and object life-time control Bartosz Golaszewski
2024-01-30 12:48 ` [PATCH 01/22] gpio: protect the list of GPIO devices with SRCU Bartosz Golaszewski
2024-01-31 9:34 ` kernel test robot
2024-01-31 12:45 ` Bartosz Golaszewski
2024-01-31 15:01 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 02/22] gpio: of: assign and read the hog pointer atomically Bartosz Golaszewski
2024-01-31 17:38 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 03/22] gpio: remove unused logging helpers Bartosz Golaszewski
2024-01-31 17:39 ` Linus Walleij
2024-01-31 18:08 ` Bartosz Golaszewski
2024-01-31 20:33 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 04/22] gpio: provide and use gpiod_get_label() Bartosz Golaszewski
2024-01-31 19:36 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 05/22] gpio: don't set label from irq helpers Bartosz Golaszewski
2024-01-31 19:38 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 06/22] gpio: add SRCU infrastructure to struct gpio_desc Bartosz Golaszewski
2024-01-31 19:35 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 07/22] gpio: protect the descriptor label with SRCU Bartosz Golaszewski
2024-01-31 19:41 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 08/22] gpio: sysfs: use gpio_device_find() to iterate over existing devices Bartosz Golaszewski
2024-01-31 19:42 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 09/22] gpio: remove gpio_lock Bartosz Golaszewski
2024-01-31 19:51 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 10/22] gpio: reinforce desc->flags handling Bartosz Golaszewski
2024-01-31 20:01 ` Linus Walleij
2024-01-31 20:35 ` Linus Walleij
2024-02-01 18:30 ` Bartosz Golaszewski
2024-01-30 12:48 ` [PATCH 11/22] gpio: remove unneeded code from gpio_device_get_desc() Bartosz Golaszewski
2024-01-31 20:02 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 12/22] gpio: sysfs: extend the critical section for unregistering sysfs devices Bartosz Golaszewski
2024-01-31 20:06 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 13/22] gpio: sysfs: pass the GPIO device - not chip - to sysfs callbacks Bartosz Golaszewski
2024-01-31 20:09 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 14/22] gpio: cdev: replace gpiochip_get_desc() with gpio_device_get_desc() Bartosz Golaszewski
2024-01-31 20:10 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 15/22] gpio: cdev: don't access gdev->chip if it's not needed Bartosz Golaszewski
2024-01-31 20:11 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 16/22] gpio: reduce the functionality of validate_desc() Bartosz Golaszewski
2024-01-31 20:16 ` Linus Walleij
2024-01-31 20:19 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 17/22] gpio: remove unnecessary checks from gpiod_to_chip() Bartosz Golaszewski
2024-01-30 12:48 ` Bartosz Golaszewski [this message]
2024-01-31 20:17 ` [PATCH 18/22] gpio: add the can_sleep flag to struct gpio_device Linus Walleij
2024-01-30 12:48 ` [PATCH 19/22] gpio: add SRCU infrastructure " Bartosz Golaszewski
2024-01-30 12:48 ` [PATCH 20/22] gpio: protect the pointer to gpio_chip in gpio_device with SRCU Bartosz Golaszewski
2024-01-31 0:41 ` kernel test robot
2024-01-31 8:15 ` Bartosz Golaszewski
2024-01-31 2:20 ` kernel test robot
2024-01-31 9:02 ` Bartosz Golaszewski
2024-01-31 9:24 ` Paul E. McKenney
2024-01-31 9:28 ` Bartosz Golaszewski
2024-01-31 9:41 ` Bartosz Golaszewski
2024-01-31 9:42 ` Paul E. McKenney
2024-01-31 10:17 ` brgl
2024-01-31 11:00 ` Paul E. McKenney
2024-01-31 12:23 ` Bartosz Golaszewski
2024-01-31 20:23 ` Linus Walleij
2024-02-01 5:03 ` Dan Carpenter
2024-02-01 7:57 ` Bartosz Golaszewski
2024-01-30 12:48 ` [PATCH 21/22] gpio: remove the RW semaphore from the GPIO device Bartosz Golaszewski
2024-01-31 20:24 ` Linus Walleij
2024-01-30 12:48 ` [PATCH 22/22] gpio: mark unsafe gpio_chip manipulators as deprecated Bartosz Golaszewski
2024-01-31 20:29 ` Linus Walleij
2024-02-01 9:14 ` Bartosz Golaszewski
2024-01-31 20:32 ` [PATCH 00/22] gpio: rework locking and object life-time control Linus Walleij
2024-02-01 8:43 ` 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=20240130124828.14678-19-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=elder@linaro.org \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=warthog618@gmail.com \
--cc=wsa@the-dreams.de \
/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).