gpiolib: legacy: Allow *gpio_request_one() to die independently
cover gpiolib: legacy: Allow *gpio_request_one() to die independently
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(-)
Signature · 1 line
2.50.1
PATCH 1/2 gpiolib: legacy: Make sure we kill gpio_request_one() first
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.
--- drivers/gpio/gpiolib-legacy.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpio/gpiolib-legacy.c +4 -14
@@ -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);
Signature · 1 line
2.50.1
PATCH 2/2 gpiolib: legacy: Allow to kill devm_gpio_request_one() independently
In reply to Andy ShevchenkoAllow to kill devm_gpio_request_one() independently by converting it to use legacy APIs that will be alive a bit longer.
--- drivers/gpio/gpiolib-legacy.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/gpio/gpiolib-legacy.c +12 -14
@@ -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);
Signature · 1 line
2.50.1
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 9 lines · Andy Shevchenko
Allow
*gpio_request_one()to die independently and make sure thegpio_request_one()gone first (beforegpio_request()removal). Currently thedevm_gpio_request_one()depends ongpio_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,
Signature · 1 line
Bartosz Golaszewski <[email protected]>