Commit 8c0fca81 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Linus Walleij

gpiolib: safer implementation of desc_to_gpio()

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: default avatarAlexandre Courbot <acourbot@nvidia.com>
Reported-by: default avatarDr. H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 03d152d5
...@@ -136,7 +136,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio) ...@@ -136,7 +136,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio)
*/ */
static int desc_to_gpio(const struct gpio_desc *desc) static int desc_to_gpio(const struct gpio_desc *desc)
{ {
return desc->chip->base + gpio_chip_hwgpio(desc); return desc - &gpio_desc[0];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment