[PATCH 0/5] gpio: refactor of_parse_own_gpio() and of_get_named_gpiod_flags()
From: Masahiro Yamada
Date: Tue Jun 14 2016 - 06:07:58 EST
I found one bug in of_parse_own_gpio(); of_gpiochip_find_and_xlate()
fills gg_data->out_gpio with an error pointer if the .of_xlate()
callback fails, but of_parse_own_gpio() only checks whether the
out_gpio is NULL. This is a problem because the error pointer might
be passed to the desc_to_gpio() in the failure path.
At first, I was trying to fix it with the following patch:
@@ -165,6 +165,9 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
return ERR_PTR(ret);
gpiochip_find(&gg_data, of_gpiochip_find_and_xlate);
+ if (IS_ERR(gg_data.out_gpio)){
+ return gg_data.out_gpio;
+ }
if (!gg_data.out_gpio) {
if (np->parent == np)
return ERR_PTR(-ENXIO);
But, after reading this code around, I thought it was more complex
than needed. So, I decided to clean-up it instead of fix the bug.
Talking about of_parse_own_gpio(), does it need to call gpiochip_find()
in the first place?
The caller of this function, of_gpiochip_scan_gpios() already knows the
gpio_chip. I want to make the implementation more straight-forward.
Masahiro Yamada (5):
gpio: of: optimize "gpios" property parsing of of_parse_own_gpio()
gpio: of: drop needless gpio_chip look-up in of_parse_own_gpio()
gpio: of: move chip->of_gpio_n_cells checking to of_gpiochip_add()
gpio: of: remove of_gpiochip_and_xlate() and struct gg_data
gpio: of: factor out common code to a new helper function
drivers/gpio/gpiolib-of.c | 126 +++++++++++++++++++++-------------------------
1 file changed, 58 insertions(+), 68 deletions(-)
--
1.9.1