gpio: rewrite gpiochip_offset_to_desc()
authorAlexandre Courbot <[email protected]>
Tue, 3 Dec 2013 03:31:11 +0000 (12:31 +0900)
committerLinus Walleij <[email protected]>
Wed, 4 Dec 2013 12:45:29 +0000 (13:45 +0100)
gpiochip_offset_to_desc() was using gpio_to_desc(), which directly
addresses the global GPIO array we are hoping to get rid of someday.
Reimplement it using the descriptor array of the chip itself, after
checking the requested offset is within the valid bounds of the chip.

Signed-off-by: Alexandre Courbot <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
drivers/gpio/gpiolib.c

index 4e10b10d3ddde47332f525285e1c549bd9a2c22f..c6326e44e2c0b86450ec2df4295224d1ee8a398e 100644 (file)
@@ -150,9 +150,10 @@ EXPORT_SYMBOL_GPL(gpio_to_desc);
 static struct gpio_desc *gpiochip_offset_to_desc(struct gpio_chip *chip,
                                                 unsigned int offset)
 {
-       unsigned int gpio = chip->base + offset;
+       if (offset >= chip->ngpio)
+               return ERR_PTR(-EINVAL);
 
-       return gpio_to_desc(gpio);
+       return &chip->desc[offset];
 }
 
 /**