Commit 1d267ea6 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Greg Kroah-Hartman

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: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9e9f079c
...@@ -94,27 +94,20 @@ struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx) ...@@ -94,27 +94,20 @@ struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for (i = 0; i < UART_GPIO_MAX; i++) { for (i = 0; i < UART_GPIO_MAX; i++) {
gpios->gpio[i] = devm_gpiod_get_index(dev, enum gpiod_flags flags;
mctrl_gpios_desc[i].name,
idx);
/*
* The GPIOs are maybe not all filled,
* this is not an error.
*/
if (IS_ERR_OR_NULL(gpios->gpio[i]))
continue;
if (mctrl_gpios_desc[i].dir_out) if (mctrl_gpios_desc[i].dir_out)
err = gpiod_direction_output(gpios->gpio[i], 0); flags = GPIOD_OUT_LOW;
else else
err = gpiod_direction_input(gpios->gpio[i]); flags = GPIOD_IN;
if (err) {
dev_dbg(dev, "Unable to set direction for %s GPIO", gpios->gpio[i] =
mctrl_gpios_desc[i].name); devm_gpiod_get_index_optional(dev,
devm_gpiod_put(dev, gpios->gpio[i]); mctrl_gpios_desc[i].name,
gpios->gpio[i] = NULL; idx, flags);
}
if (IS_ERR(gpios->gpio[i]))
return PTR_ERR(gpios->gpio[i]);
} }
return gpios; return gpios;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment