[PATCH] i2c-mux-gpio: Check gpio_direction_output return value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



gpio_direction_output() may fail, check for that and deal with it
appropriately. Also log an error message if gpio_request() fails.

Signed-off-by: Jean Delvare <khali@xxxxxxxxxxxx>
Cc: Peter Korsgaard <peter.korsgaard@xxxxxxxxx>
Cc: Wolfram Sang <wsa@xxxxxxxxxxxxx>
---
 drivers/i2c/muxes/i2c-mux-gpio.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

--- linux-3.7.orig/drivers/i2c/muxes/i2c-mux-gpio.c	2012-12-15 14:52:47.368991730 +0100
+++ linux-3.7/drivers/i2c/muxes/i2c-mux-gpio.c	2013-03-03 14:27:21.003905620 +0100
@@ -123,10 +123,21 @@ static int __devinit i2c_mux_gpio_probe(
 
 	for (i = 0; i < pdata->n_gpios; i++) {
 		ret = gpio_request(gpio_base + pdata->gpios[i], "i2c-mux-gpio");
-		if (ret)
+		if (ret) {
+			dev_err(&pdev->dev, "Failed to request GPIO %d\n",
+				pdata->gpios[i]);
 			goto err_request_gpio;
-		gpio_direction_output(gpio_base + pdata->gpios[i],
-				      initial_state & (1 << i));
+		}
+
+		ret = gpio_direction_output(gpio_base + pdata->gpios[i],
+					    initial_state & (1 << i));
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to set direction of GPIO %d to output\n",
+				pdata->gpios[i]);
+			i++;
+			goto err_request_gpio;
+		}
 	}
 
 	for (i = 0; i < pdata->n_values; i++) {

-- 
Jean Delvare
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux