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

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