linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio()
@ 2013-10-04 17:59 Alexandre Courbot
  2013-10-04 17:59 ` [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER Alexandre Courbot
  2013-10-11 14:25 ` [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandre Courbot @ 2013-10-04 17:59 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dr. H. Nikolaus Schaller, linux-gpio, linux-kernel, gnurou,
	Alexandre Courbot

The current implementation of desc_to_gpio() relies on the chip pointer
to be set to a valid value in order to compute the GPIO number. This
was done in the hope that we can get rid of the gpio_desc global array,
but this is not happening anytime soon.

This patch reimplements desc_to_gpio() in a fashion similar to that of
gpio_to_desc(). As a result, desc_to_gpio(gpio_to_desc(gpio)) == gpio is
now always true. This allows to call desc_to_gpio() on non-initialized
descriptors as some error-handling code currently does.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 86ef346..f330631 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -136,7 +136,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio)
  */
 static int desc_to_gpio(const struct gpio_desc *desc)
 {
-	return desc->chip->base + gpio_chip_hwgpio(desc);
+	return desc - &gpio_desc[0];
 }
 
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER
  2013-10-04 17:59 [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Alexandre Courbot
@ 2013-10-04 17:59 ` Alexandre Courbot
  2013-10-11 14:28   ` Linus Walleij
  2013-10-11 14:25 ` [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Courbot @ 2013-10-04 17:59 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dr. H. Nikolaus Schaller, linux-gpio, linux-kernel, gnurou,
	Alexandre Courbot

Patch be1a4b brought some improvements to the GPIO error handling code,
but also changed the return value of gpiod_request() when called on a
not yet initialized GPIO descriptor: it now returns -EINVAL instead of
-EPROBE_DEFER, and this affects some drivers.

This patch restores the original behavior for gpiod_request(). It is
safe to do so now that desc_to_gpio() does not rely on the GPIO
descriptor to be initialized. Other functions changed by patch be1a4b
do not see their return value affected, so these are not reverted.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/gpio/gpiolib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f330631..0dee0e0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1398,7 +1398,7 @@ static int gpiod_request(struct gpio_desc *desc, const char *label)
 	int			status = -EPROBE_DEFER;
 	unsigned long		flags;
 
-	if (!desc || !desc->chip) {
+	if (!desc) {
 		pr_warn("%s: invalid GPIO\n", __func__);
 		return -EINVAL;
 	}
@@ -1406,6 +1406,8 @@ static int gpiod_request(struct gpio_desc *desc, const char *label)
 	spin_lock_irqsave(&gpio_lock, flags);
 
 	chip = desc->chip;
+	if (chip == NULL)
+		goto done;
 
 	if (!try_module_get(chip->owner))
 		goto done;
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio()
  2013-10-04 17:59 [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Alexandre Courbot
  2013-10-04 17:59 ` [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER Alexandre Courbot
@ 2013-10-11 14:25 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2013-10-11 14:25 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Dr. H. Nikolaus Schaller, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, Alexandre Courbot

On Fri, Oct 4, 2013 at 7:59 PM, Alexandre Courbot <acourbot@nvidia.com> wrote:

> The current implementation of desc_to_gpio() relies on the chip pointer
> to be set to a valid value in order to compute the GPIO number. This
> was done in the hope that we can get rid of the gpio_desc global array,
> but this is not happening anytime soon.
>
> This patch reimplements desc_to_gpio() in a fashion similar to that of
> gpio_to_desc(). As a result, desc_to_gpio(gpio_to_desc(gpio)) == gpio is
> now always true. This allows to call desc_to_gpio() on non-initialized
> descriptors as some error-handling code currently does.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER
  2013-10-04 17:59 ` [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER Alexandre Courbot
@ 2013-10-11 14:28   ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2013-10-11 14:28 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Dr. H. Nikolaus Schaller, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, Alexandre Courbot

On Fri, Oct 4, 2013 at 7:59 PM, Alexandre Courbot <acourbot@nvidia.com> wrote:

> Patch be1a4b brought some improvements to the GPIO error handling code,
> but also changed the return value of gpiod_request() when called on a
> not yet initialized GPIO descriptor: it now returns -EINVAL instead of
> -EPROBE_DEFER, and this affects some drivers.
>
> This patch restores the original behavior for gpiod_request(). It is
> safe to do so now that desc_to_gpio() does not rely on the GPIO
> descriptor to be initialized. Other functions changed by patch be1a4b
> do not see their return value affected, so these are not reverted.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>

Patch applied.

Are these two patches regressions that need to go into fixes
for v3.12?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-11 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-04 17:59 [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Alexandre Courbot
2013-10-04 17:59 ` [PATCH 2/2] gpiolib: let gpiod_request() return -EPROBE_DEFER Alexandre Courbot
2013-10-11 14:28   ` Linus Walleij
2013-10-11 14:25 ` [PATCH 1/2] gpiolib: safer implementation of desc_to_gpio() Linus Walleij

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).