Re: [PATCH v2 4/9] gpio: sysfs: don't use driver data in sysfs callbacks for line attributes

From: Bartosz Golaszewski
Date: Mon Jun 30 2025 - 04:57:31 EST


On Fri, Jun 27, 2025 at 5:41 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
>
> On Mon, Jun 23, 2025 at 10:59:52AM +0200, Bartosz Golaszewski wrote:
> >
> > Currently each exported GPIO is represented in sysfs as a separate class
> > device. This allows us to simply use dev_get_drvdata() to retrieve the
> > pointer passed to device_create_with_groups() from sysfs ops callbacks.
> >
> > However, we're preparing to add a parallel set of per-line sysfs
> > attributes that will live inside the associated gpiochip group. They are
> > not registered as class devices and so have the parent device passed as
> > argument to their callbacks (the GPIO chip class device).
> >
> > Put the attribute structs inside the GPIO descriptor data and
> > dereference the relevant ones using container_of() in the callbacks.
> > This way, we'll be able to reuse the same code for both the legacy and
> > new GPIO attributes.
>
> ...
>
> > - struct gpiod_data *data = dev_get_drvdata(dev);
> > + struct gpiod_data *data = container_of(attr, struct gpiod_data,
> > + dir_attr);
>
> Defining once something like
>
> #define to_gpiod_data() ...
>
> we may leave this and others as one-liners.

We'd need one per every attribute. Look closer, we do get a different
attr address in every pair of callbacks.

>
> ...
>
> > + attrs[GPIO_SYSFS_LINE_ATTR_ACTIVE_LOW] =
> > + &data->active_low_attr.attr;
>
> What's the point of two lines here?
>

I tend to stick with the 80 chars limit even though it was lifted.

Bart

> --
> With Best Regards,
> Andy Shevchenko
>
>