[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMRc=Md4f_CMWKEr+k7z0NosnDmXtM1WO1ONyzE0j0OgN2W3vw@mail.gmail.com>
Date: Mon, 30 Jun 2025 15:39:20 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Ahmad Fatoum <a.fatoum@...gutronix.de>, Kent Gibson <warthog618@...il.com>,
Jan Lübbe <jlu@...gutronix.de>, Marek Vasut <marex@...x.de>,
Geert Uytterhoeven <geert+renesas@...der.be>, Linus Walleij <linus.walleij@...aro.org>,
linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v3 06/10] gpio: sysfs: don't use driver data in sysfs
callbacks for line attributes
On Mon, Jun 30, 2025 at 3:28 PM Andy Shevchenko
<andriy.shevchenko@...el.com> wrote:
>
> On Mon, Jun 30, 2025 at 02:37:13PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> >
> > 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);
>
> > - struct gpiod_data *data = dev_get_drvdata(dev);
> > + struct gpiod_data *data = container_of(attr, struct gpiod_data,
> > + dir_attr);
>
> I still think that bunch of definitions to wrap contaner_of():s will help.
> Note, two of them you are using even in the code below, besides the attribute
> show()/store() cases.
>
I think this is overkill, the container_of() macro is pretty explicit
and having 4 new macros will result in more LOC in the end. I'll allow
myself to keep this as is.
Bart
> ...
>
> > + if (strcmp(attr->name, "direction") == 0) {
> > + data = container_of(dev_attr, struct gpiod_data, dir_attr);
> > +
> > + if (!data->direction_can_change)
> > mode = 0;
>
> data = dir_attr_to_gpiod_data(dev_attr);
> if (!data->direction_can_change)
> mode = 0;
>
> > + } else if (strcmp(attr->name, "edge") == 0) {
>
> > + data = container_of(dev_attr, struct gpiod_data, edge_attr);
> > +
> > + if (gpiod_to_irq(data->desc) < 0)
> > mode = 0;
>
> In the similar way:
>
> data = edge_attr_to_gpiod_data(dev_attr);
> if (gpiod_to_irq(data->desc) < 0)
> mode = 0;
>
> > + if (!data->direction_can_change &&
> > + test_bit(FLAG_IS_OUT, &data->desc->flags))
> > mode = 0;
> > }
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Powered by blists - more mailing lists