Re: [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver

From: Linus Walleij
Date: Tue Sep 23 2014 - 11:38:57 EST


On Thu, Sep 18, 2014 at 11:03 AM, Gernot Vormayr <gvormayr@xxxxxxxxx> wrote:

> If one adds 'gpio-controller;' to the chip in the devicetree, then
> initialization fails with 'gpiochip_find_base: cannot find free range',
> because ngpio is 0. This patch fixes the bug.
>
> Tested on ml507 board.
>
> Signed-off-by: Gernot Vormayr <gvormayr@xxxxxxxxx>
> ---
> drivers/gpio/gpio-xilinx.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
> index 1248186..4606ad2 100644
> --- a/drivers/gpio/gpio-xilinx.c
> +++ b/drivers/gpio/gpio-xilinx.c
> @@ -197,6 +197,7 @@ static int xgpio_of_probe(struct device_node *np)
> struct xgpio_instance *chip;
> int status = 0;
> const u32 *tree_info;
> + u32 ngpio;
>
> chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> if (!chip)
> @@ -215,8 +216,9 @@ static int xgpio_of_probe(struct device_node *np)
> chip->mmchip.gc.ngpio = 32;

Delete that line ^

>
> /* Check device node and parent device node for device width */
> - of_property_read_u32(np, "xlnx,gpio-width",
> - (u32 *)&chip->mmchip.gc.ngpio);
> + status = of_property_read_u32(np, "xlnx,gpio-width", &ngpio);
> + if (status == 0)
> + chip->mmchip.gc.ngpio = (u16)ngpio;

Rewrite like this:

if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio))
ngpio = 32;
chip->mmchip.gc.ngpio = (u16)ngpio;

>
> spin_lock_init(&chip->gpio_lock);
>
> @@ -262,8 +264,9 @@ static int xgpio_of_probe(struct device_node *np)
> chip->mmchip.gc.ngpio = 32;
>
> /* Check device node and parent device node for device width */
> - of_property_read_u32(np, "xlnx,gpio2-width",
> - (u32 *)&chip->mmchip.gc.ngpio);
> + status = of_property_read_u32(np, "xlnx,gpio2-width", &ngpio);
> + if (status == 0)
> + chip->mmchip.gc.ngpio = (u16)ngpio;

Same comment.

The fact that the same code appears in two places tells us something
is not quite right. Can you look into consolidating this (in a separate
patch)?

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/