[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMRc=MeYiiWaaqRtSjRBfaWGFtZCPWCjYk+ZrX5TwicNq9MQeA@mail.gmail.com>
Date: Fri, 6 Oct 2023 21:07:49 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andy Shevchenko <andy@...nel.org>
Cc: Linus Walleij <linus.walleij@...aro.org>,
linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
Dipen Patel <dipenp@...dia.com>,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [RFC/RFT PATCH] gpiolib: reverse-assign the fwnode to struct gpio_chip
On Fri, Oct 6, 2023 at 3:24 PM Andy Shevchenko <andy@...nel.org> wrote:
>
> On Fri, Oct 06, 2023 at 01:51:47PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> >
> > struct gpio_chip is not only used to carry the information needed to
> > set-up a GPIO device but is also used in all GPIOLIB callbacks and is
> > passed to the matching functions of lookup helpers.
> >
> > In that last case, it is currently impossible to match a GPIO device by
> > fwnode unless it was explicitly assigned to the chip in the provider
> > code. If the fwnode is taken from the parent device, the pointer in
> > struct gpio_chip will remain NULL.
> >
> > If we have a parent device but gc->fwnode was not assigned by the
> > provider, let's assign it ourselves so that lookup by fwnode can work in
> > all cases.
>
> ...
>
> > + gc->fwnode = parent_fwnode;
>
> Ah, this is basically reverts my commit, the whole idea of which was to go
> towards constant struct gpio_chip object that is supplied by a provider.
>
Then this idea was wrong in the first place and that goal will never
be achieved. Whether that's a correct approach is questionable but
struct gpio_chip has become so much more than a simple config
structure and - given how ubiquitous GPIO providers are throughout the
different subsystems of the kernel - it'll stay that way unless we're
ready to rebuild every GPIO provider in linux.
The best we can do now is at least make its usage safe. Meaning: it's
a structure with which providers will interact using GPIOLIB callbacks
which will in turn assure that during the execution of any function
taking struct gpio_chip as argument, it will remain alive and
protected from concurrent access.
The providers however will continue to use gpio_chip for many
purposes. One of such purposes is matching the GPIO device BY its
backing gpio_chip structure. It not having the same fwnode in this
particular case is an inconsistency rather than design IMO.
I don't see any good reason for it not having the fwnode assigned.
User calling gpio_device_find() will have to jump through hoops in
order to match the device by fwnode (include gpiolib.h and dereference
gpiodev?) but it could be very easily facilitated by just assigning it
at registration-time - just like we assign a whole bunch of other
pointers and data structures.
Bart
> --
> With Best Regards,
> Andy Shevchenko
>
>
Powered by blists - more mailing lists