Skip to content

Commit 1d267ea

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
serial: mctrl-gpio: simplify init routine
Instead of ignoring errors returned by devm_gpiod_get_index use devm_gpiod_get_index_optional which results in slightly more strict error handling which is good. Also use the fourth parameter to devm_gpiod_get_index_optional to be able to drop the explicit direction setting. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9e9f079 commit 1d267ea

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

drivers/tty/serial/serial_mctrl_gpio.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,20 @@ struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
9494
return ERR_PTR(-ENOMEM);
9595

9696
for (i = 0; i < UART_GPIO_MAX; i++) {
97-
gpios->gpio[i] = devm_gpiod_get_index(dev,
98-
mctrl_gpios_desc[i].name,
99-
idx);
100-
101-
/*
102-
* The GPIOs are maybe not all filled,
103-
* this is not an error.
104-
*/
105-
if (IS_ERR_OR_NULL(gpios->gpio[i]))
106-
continue;
97+
enum gpiod_flags flags;
10798

10899
if (mctrl_gpios_desc[i].dir_out)
109-
err = gpiod_direction_output(gpios->gpio[i], 0);
100+
flags = GPIOD_OUT_LOW;
110101
else
111-
err = gpiod_direction_input(gpios->gpio[i]);
112-
if (err) {
113-
dev_dbg(dev, "Unable to set direction for %s GPIO",
114-
mctrl_gpios_desc[i].name);
115-
devm_gpiod_put(dev, gpios->gpio[i]);
116-
gpios->gpio[i] = NULL;
117-
}
102+
flags = GPIOD_IN;
103+
104+
gpios->gpio[i] =
105+
devm_gpiod_get_index_optional(dev,
106+
mctrl_gpios_desc[i].name,
107+
idx, flags);
108+
109+
if (IS_ERR(gpios->gpio[i]))
110+
return PTR_ERR(gpios->gpio[i]);
118111
}
119112

120113
return gpios;

0 commit comments

Comments
 (0)