Re: Bug introduced in the of_get_named_gpiod_flags function.

From: Wojciech ZaboÅotny
Date: Mon Oct 15 2018 - 10:01:13 EST


On 13.10.2018 18:23, Linus Walleij wrote:
> On Sat, Oct 13, 2018 at 5:53 PM wzabolot@xxxxxxxxxxxxxxxxxxxxxxx
> <wzabolot@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> The question is, if there may be any other in-tree GPIO controller
>> driver that does not initialize those flags?
> So as I said, I looked over them and they all initialize
> their flags.
>
>> Anyway the current situation is somehow dangerous.
> Not very dangerous compared to much other kernel code.
>
>> Maybe the best solution would be to initialize the automatic variable in
>> the of_find_gpio?
> Patches welcom, make sure they are tested with mainline
> code and drivers.
>
> Yours.
> Linus Walleij

OK. So I suggested correction of the Xilinx GPIO driver so that it always sets the flags:

static int xgpio_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec, u32 *flags)
{
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct xgpio_instance *chip = container_of(mm_gc, struct xgpio_instance,
mmchip);
if(flags)
* flags = 0;

if (gpiospec->args[1] == chip->offset)
return gpiospec->args[0];

return -EINVAL;
}

With best regards,
Wojtek