Skip to contentSkip to conversation

gpio: rewrite gpiochip_offset_to_desc()

PATCH In review Alexandre Courbot 2 participants 2 messages Dec 3, 2013 – Dec 4, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: rewrite gpiochip_offset_to_desc()

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.

---
 drivers/gpio/gpiolib.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +3 -2
index 4ca103965d8c..ea95b42c6154 100644
@@ -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];
 }
 
 /**
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 6 lines · Alexandre Courbot

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.

Patch applied.

Yours,
Linus Walleij