Commit 8c0fca8153224822121c85a64d6401903b9e4690

Authored by Alexandre Courbot
Committed by Linus Walleij
1 parent 03d152d558

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: Alexandre Courbot <acourbot@nvidia.com>
Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

drivers/gpio/gpiolib.c
... ... @@ -136,7 +136,7 @@
136 136 */
137 137 static int desc_to_gpio(const struct gpio_desc *desc)
138 138 {
139   - return desc->chip->base + gpio_chip_hwgpio(desc);
  139 + return desc - &gpio_desc[0];
140 140 }
141 141  
142 142