* [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently
@ 2025-11-12 9:32 Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-12 9:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski
Allow *gpio_request_one() to die independently and make sure
the gpio_request_one() gone first (before gpio_request() removal).
Currently the devm_gpio_request_one() depends on gpio_request_one().
Open code the latter in the former to break the dependency. Also
convert the latter to use legacy APIs, so we can kill it first
as it's not only the logical move, but an easier task due to less
amount of the leftover users in the kernel.
Besides that, we gain a few LoCs with this small refactoring, which
I consider a positive change alone.
Andy Shevchenko (2):
gpiolib: legacy: Make sure we kill gpio_request_one() first
gpiolib: legacy: Allow to kill devm_gpio_request_one() independently
drivers/gpio/gpiolib-legacy.c | 44 +++++++++++++----------------------
1 file changed, 16 insertions(+), 28 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1 1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first
2025-11-12 9:32 [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Andy Shevchenko
@ 2025-11-12 9:32 ` Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 2/2] gpiolib: legacy: Allow to kill devm_gpio_request_one() independently Andy Shevchenko
2025-11-17 9:57 ` [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-12 9:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski
Make sure we kill gpio_request_one() first by converting it to
use legacy APIs that will be alive a bit longer. In particular,
this also shows the code we will use in another function to make
it die independently.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-legacy.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c
index 3bc93ccadb5b..35cb7fca634e 100644
--- a/drivers/gpio/gpiolib-legacy.c
+++ b/drivers/gpio/gpiolib-legacy.c
@@ -34,30 +34,20 @@ EXPORT_SYMBOL_GPL(gpio_free);
*/
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
{
- struct gpio_desc *desc;
int err;
- /* Compatibility: assume unavailable "valid" GPIOs will appear later */
- desc = gpio_to_desc(gpio);
- if (!desc)
- return -EPROBE_DEFER;
-
- err = gpiod_request(desc, label);
+ err = gpio_request(gpio, label);
if (err)
return err;
if (flags & GPIOF_IN)
- err = gpiod_direction_input(desc);
+ err = gpio_direction_input(gpio);
else
- err = gpiod_direction_output_raw(desc, !!(flags & GPIOF_OUT_INIT_HIGH));
+ err = gpio_direction_output(gpio, !!(flags & GPIOF_OUT_INIT_HIGH));
if (err)
- goto free_gpio;
+ gpio_free(gpio);
- return 0;
-
- free_gpio:
- gpiod_free(desc);
return err;
}
EXPORT_SYMBOL_GPL(gpio_request_one);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 2/2] gpiolib: legacy: Allow to kill devm_gpio_request_one() independently
2025-11-12 9:32 [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first Andy Shevchenko
@ 2025-11-12 9:32 ` Andy Shevchenko
2025-11-17 9:57 ` [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-12 9:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski
Allow to kill devm_gpio_request_one() independently by converting it
to use legacy APIs that will be alive a bit longer.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-legacy.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c
index 35cb7fca634e..ef3f2ef30cf2 100644
--- a/drivers/gpio/gpiolib-legacy.c
+++ b/drivers/gpio/gpiolib-legacy.c
@@ -68,11 +68,9 @@ int gpio_request(unsigned gpio, const char *label)
}
EXPORT_SYMBOL_GPL(gpio_request);
-static void devm_gpio_release(struct device *dev, void *res)
+static void devm_gpio_release(void *gpio)
{
- unsigned *gpio = res;
-
- gpio_free(*gpio);
+ gpio_free((unsigned)(unsigned long)gpio);
}
/**
@@ -90,22 +88,22 @@ static void devm_gpio_release(struct device *dev, void *res)
int devm_gpio_request_one(struct device *dev, unsigned gpio,
unsigned long flags, const char *label)
{
- unsigned *dr;
int rc;
- dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
- if (!dr)
- return -ENOMEM;
+ rc = gpio_request(gpio, label);
+ if (rc)
+ return rc;
+
+ if (flags & GPIOF_IN)
+ rc = gpio_direction_input(gpio);
+ else
+ rc = gpio_direction_output(gpio, !!(flags & GPIOF_OUT_INIT_HIGH));
- rc = gpio_request_one(gpio, flags, label);
if (rc) {
- devres_free(dr);
+ gpio_free(gpio);
return rc;
}
- *dr = gpio;
- devres_add(dev, dr);
-
- return 0;
+ return devm_add_action_or_reset(dev, devm_gpio_release, (void *)(unsigned long)gpio);
}
EXPORT_SYMBOL_GPL(devm_gpio_request_one);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently
2025-11-12 9:32 [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 2/2] gpiolib: legacy: Allow to kill devm_gpio_request_one() independently Andy Shevchenko
@ 2025-11-17 9:57 ` Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2025-11-17 9:57 UTC (permalink / raw)
To: linux-gpio, linux-kernel, Andy Shevchenko
Cc: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Wed, 12 Nov 2025 10:32:00 +0100, Andy Shevchenko wrote:
> Allow *gpio_request_one() to die independently and make sure
> the gpio_request_one() gone first (before gpio_request() removal).
> Currently the devm_gpio_request_one() depends on gpio_request_one().
> Open code the latter in the former to break the dependency. Also
> convert the latter to use legacy APIs, so we can kill it first
> as it's not only the logical move, but an easier task due to less
> amount of the leftover users in the kernel.
>
> [...]
Applied, thanks!
[1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first
https://git.kernel.org/brgl/linux/c/61e1fd2abca4c551fb40afcb733a31de1991c656
[2/2] gpiolib: legacy: Allow to kill devm_gpio_request_one() independently
https://git.kernel.org/brgl/linux/c/ade570c138a509c11b5d016a227009f2f399fd4a
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-17 9:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 9:32 [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 1/2] gpiolib: legacy: Make sure we kill gpio_request_one() first Andy Shevchenko
2025-11-12 9:32 ` [PATCH v1 2/2] gpiolib: legacy: Allow to kill devm_gpio_request_one() independently Andy Shevchenko
2025-11-17 9:57 ` [PATCH v1 0/2] gpiolib: legacy: Allow *gpio_request_one() to die independently Bartosz Golaszewski
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).