Re: [PATCH] gpiolib: fix hogs with multiple lines
From: Bartosz Golaszewski
Date: Thu Mar 26 2026 - 10:03:13 EST
On Wed, Mar 25, 2026 at 7:42 PM Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:
>
> Hi Bartosz,
>
> On Wed, 25 Mar 2026 at 11:18, Bartosz Golaszewski
> <bartosz.golaszewski@xxxxxxxxxxxxxxxx> wrote:
> > After moving GPIO hog handling into GPIOLIB core, we accidentally stopped
> > supporting devicetree hog definitions with multiple lines like so:
> >
> > hog {
> > gpio-hog;
> > gpios = <3 0>, <4 GPIO_ACTIVE_LOW>;
> > output-high;
> > line-name = "foo";
> > };
> >
> > Restore this functionality to fix reported regressions.
> >
> > Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core")
> > Reported-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> > Closes: https://lore.kernel.org/all/CAMuHMdX6RuZXAozrF5m625ZepJTVVr4pcyKczSk12MedWvoejw@xxxxxxxxxxxxxx/
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
>
> Thanks, that fixes the issue I saw on Marzen
> Tested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
>
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -938,12 +938,12 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
> > struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);
> > struct fwnode_reference_args gpiospec;
> > enum gpiod_flags dflags;
> > + const char *name = NULL;
> > struct gpio_desc *desc;
> > unsigned long lflags;
> > - const char *name;
> > + size_t num_hogs;
> > int ret, argc;
> > - u32 gpios[3]; /* We support up to three-cell bindings. */
> > - u32 cells;
> > + u32 cells = 0;
>
> Shouldn't the default be 2?
>
For DT I suppose there's no real "default" but it does make sense to
set it to 2 for the generic fwnode path.
> >
> > lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
> > dflags = GPIOD_ASIS;
> > @@ -952,43 +952,21 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
> > argc = fwnode_property_count_u32(fwnode, "gpios");
> > if (argc < 0)
> > return argc;
> > - if (argc > 3)
> > +
> > + ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells);
>
> Should this call be protected by is_of_node(), like in the old code?
>
Not necessarily. We may end up using it with software nodes for
instance. I'd keep it global.
> > + if ((ret && is_of_node(fwnode)) || (!ret && (argc % cells)))
> > return -EINVAL;
> >
> > + num_hogs = ret ? 1 : (argc / cells);
>
> While you avoid modulo and division by zero due to the check for ret,
> using a default would let you always validate argc against cells,
> and remove the need for special casing num_hogs.
>
> > +
> > + u32 *gpios __free(kfree) = kcalloc(argc, sizeof(u32), GFP_KERNEL);
>
> kzalloc_objs()?
>
True.
Bart