Skip to contentSkip to conversation

MX1/MX2: -EINVAL overwritten in second iteration in mxc_gpio_setup_multiple_pins()

PATCH In review Roel Kluin 2 participants 2 messages Feb 3, 2010

Subsystems (3)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 MX1/MX2: -EINVAL overwritten in second iteration in mxc_gpio_setup_multiple_pins()

Due to the `ret = gpio_request()' below in the loop, the initial -EINVAL value of ret is overwritten.

---
Not 100% sure this is needed, please review. One more question: is it ok to return 0 when count is 0 (and nothing is done)?

arch/arm/plat-mxc/iomux-mx1-mx2.c +4 -2
index a37163c..25023ac 100644
@@ -116,14 +116,16 @@ int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
 	int i;
 	unsigned gpio;
 	unsigned mode;
-	int ret = -EINVAL;
+	int ret;
 
 	for (i = 0; i < count; i++) {
 		gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
 		mode = *p & ~(GPIO_PIN_MASK | GPIO_PORT_MASK);
 
-		if (gpio >= (GPIO_PORT_MAX + 1) * 32)
+		if (gpio >= (GPIO_PORT_MAX + 1) * 32) {
+			ret = -EINVAL;
 			goto setup_error;
+		}
 
 		ret = gpio_request(gpio, label);
 		if (ret)
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Roel Kluin

Due to the `ret = gpio_request()' below in the loop, the initial -EINVAL value of ret is overwritten.

Quoted 3 lines

---
Not 100% sure this is needed, please review. One more question: is it ok to return 0 when count is 0 (and nothing is done)?

I'd say yes. If you want nothing from me, I can say I gave you all you wanted without doing anything.

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |