瀏覽代碼

leds: lp8860: make use of devm_gpiod_get_optional

The probe function open coded a bad variant of devm_gpiod_get_optional
using devm_gpiod_get and just ignoring all errors.
In contrast to that devm_gpiod_get_optional returns NULL if there was no
corresponding gpio specified in the device tree (or ACPI table) and
fails if there is an error (or GPIOLIB is not enabled).

Moreover since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*()
functions) which appeared in v3.17-rc1, the gpiod_get* functions take an
additional parameter that allows to specify direction and initial value
for output which allows some simplification.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Uwe Kleine-König 10 年之前
父節點
當前提交
eb2294c343
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      drivers/leds/leds-lp8860.c

+ 7 - 5
drivers/leds/leds-lp8860.c

@@ -391,11 +391,13 @@ static int lp8860_probe(struct i2c_client *client,
 		}
 	}
 
-	led->enable_gpio = devm_gpiod_get(&client->dev, "enable");
-	if (IS_ERR(led->enable_gpio))
-		led->enable_gpio = NULL;
-	else
-		gpiod_direction_output(led->enable_gpio, 0);
+	led->enable_gpio = devm_gpiod_get_optional(&client->dev,
+						   "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(led->enable_gpio)) {
+		ret = PTR_ERR(led->enable_gpio);
+		dev_err(&client->dev, "Failed to get enable gpio: %d\n", ret);
+		return ret;
+	}
 
 	led->regulator = devm_regulator_get(&client->dev, "vled");
 	if (IS_ERR(led->regulator))