mbox series

[v2,0/2] gpiolib: Fix gpio_lookup_flags mess and add Return sections

Message ID 20240408231727.396452-1-andriy.shevchenko@linux.intel.com
Headers show
Series gpiolib: Fix gpio_lookup_flags mess and add Return sections | expand

Message

Andy Shevchenko April 8, 2024, 11:12 p.m. UTC
While reviewing another patch I have realised that enum
gpio_lookup_flags messes up with GPIO_* flags definitions.
Hence the first patch fix. Second one is an updated version
of adding Return sections to the kernel-doc.

The series is made in assumption that the patches will land in this
order, but if applied separately, e.g., one to for-current and one to
for-next branches, no conflicts should appear.

In v2:
- new patch 1
- replaces error-code by errno (Randy)
- added tags to patch 2 (Randy)

Andy Shevchenko (2):
  gpiolib: Fix a mess with the GPIO_* flags
  gpiolib: Update the kernel documentation - add Return sections

 drivers/gpio/gpiolib-acpi.c                   |  22 ++-
 drivers/gpio/gpiolib-cdev.c                   |   8 +-
 drivers/gpio/gpiolib-devres.c                 |  44 ++++-
 drivers/gpio/gpiolib-legacy.c                 |   3 +
 drivers/gpio/gpiolib-of.c                     |  53 ++++--
 drivers/gpio/gpiolib-swnode.c                 |   4 +-
 drivers/gpio/gpiolib-sysfs.c                  |   6 +-
 drivers/gpio/gpiolib.c                        | 165 ++++++++++++++----
 .../broadcom/brcm80211/brcmsmac/led.c         |   2 +-
 include/linux/gpio/driver.h                   |   3 +-
 include/linux/gpio/machine.h                  |  20 +--
 11 files changed, 245 insertions(+), 85 deletions(-)

Comments

Bartosz Golaszewski April 9, 2024, 9:42 a.m. UTC | #1
On Tue, Apr 9, 2024 at 1:17 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The GPIO_* flag definitions are *almost* duplicated in two files
> (with unmatches OPEN_SOURCE / OPEN_DRAIN). Moreover, some code relies
> on one set of definitions while the rest is on the other. Clean up
> this mess by providing only one source of the definitions to all.
>
> Fixes: b424808115cb ("brcm80211: brcmsmac: Move LEDs to GPIO descriptors")
> Fixes: 5923ea6c2ce6 ("gpio: pass lookup and descriptor flags to request_own")
> Fixes: fed7026adc7c ("gpiolib: Make use of enum gpio_lookup_flags consistent")
> Fixes: 4c0facddb7d8 ("gpio: core: Decouple open drain/source flag with active low/high")
> Fixes: 69d301fdd196 ("gpio: add DT bindings for existing consumer flags")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib-of.c                     |  5 ++---
>  drivers/gpio/gpiolib.c                        |  8 +++-----
>  .../broadcom/brcm80211/brcmsmac/led.c         |  2 +-
>  include/linux/gpio/driver.h                   |  3 +--
>  include/linux/gpio/machine.h                  | 20 +++++--------------
>  5 files changed, 12 insertions(+), 26 deletions(-)
>

I don't think ./dt-bindings/gpio/gpio.h is the right source of these
defines for everyone - including non-OF systems. I would prefer the
ones in include/linux/gpio/machine.h be the upstream source but then
headers in include/dt-bindings/ cannot include them so my second-best
suggestion is to rename the ones in include/linux/gpio/machine.h and
treewide too. In general values from ./dt-bindings/gpio/gpio.h should
only be used in DTS sources and gpiolib-of code.

Bart
Andy Shevchenko April 9, 2024, 12:51 p.m. UTC | #2
On Tue, Apr 09, 2024 at 11:42:37AM +0200, Bartosz Golaszewski wrote:
> On Tue, Apr 9, 2024 at 1:17 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > The GPIO_* flag definitions are *almost* duplicated in two files
> > (with unmatches OPEN_SOURCE / OPEN_DRAIN). Moreover, some code relies
> > on one set of definitions while the rest is on the other. Clean up
> > this mess by providing only one source of the definitions to all.
> >
> > Fixes: b424808115cb ("brcm80211: brcmsmac: Move LEDs to GPIO descriptors")
> > Fixes: 5923ea6c2ce6 ("gpio: pass lookup and descriptor flags to request_own")
> > Fixes: fed7026adc7c ("gpiolib: Make use of enum gpio_lookup_flags consistent")
> > Fixes: 4c0facddb7d8 ("gpio: core: Decouple open drain/source flag with active low/high")
> > Fixes: 69d301fdd196 ("gpio: add DT bindings for existing consumer flags")
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/gpio/gpiolib-of.c                     |  5 ++---
> >  drivers/gpio/gpiolib.c                        |  8 +++-----
> >  .../broadcom/brcm80211/brcmsmac/led.c         |  2 +-
> >  include/linux/gpio/driver.h                   |  3 +--
> >  include/linux/gpio/machine.h                  | 20 +++++--------------
> >  5 files changed, 12 insertions(+), 26 deletions(-)
> 
> I don't think ./dt-bindings/gpio/gpio.h is the right source of these
> defines for everyone - including non-OF systems. I would prefer the
> ones in include/linux/gpio/machine.h be the upstream source but then
> headers in include/dt-bindings/ cannot include them so my second-best
> suggestion is to rename the ones in include/linux/gpio/machine.h and
> treewide too. In general values from ./dt-bindings/gpio/gpio.h should
> only be used in DTS sources and gpiolib-of code.

Then, please fix that your way. It's quite annoying issue.
Bartosz Golaszewski April 9, 2024, 12:55 p.m. UTC | #3
On Tue, Apr 9, 2024 at 2:51 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, Apr 09, 2024 at 11:42:37AM +0200, Bartosz Golaszewski wrote:
> > On Tue, Apr 9, 2024 at 1:17 AM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > The GPIO_* flag definitions are *almost* duplicated in two files
> > > (with unmatches OPEN_SOURCE / OPEN_DRAIN). Moreover, some code relies
> > > on one set of definitions while the rest is on the other. Clean up
> > > this mess by providing only one source of the definitions to all.
> > >
> > > Fixes: b424808115cb ("brcm80211: brcmsmac: Move LEDs to GPIO descriptors")
> > > Fixes: 5923ea6c2ce6 ("gpio: pass lookup and descriptor flags to request_own")
> > > Fixes: fed7026adc7c ("gpiolib: Make use of enum gpio_lookup_flags consistent")
> > > Fixes: 4c0facddb7d8 ("gpio: core: Decouple open drain/source flag with active low/high")
> > > Fixes: 69d301fdd196 ("gpio: add DT bindings for existing consumer flags")
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > ---
> > >  drivers/gpio/gpiolib-of.c                     |  5 ++---
> > >  drivers/gpio/gpiolib.c                        |  8 +++-----
> > >  .../broadcom/brcm80211/brcmsmac/led.c         |  2 +-
> > >  include/linux/gpio/driver.h                   |  3 +--
> > >  include/linux/gpio/machine.h                  | 20 +++++--------------
> > >  5 files changed, 12 insertions(+), 26 deletions(-)
> >
> > I don't think ./dt-bindings/gpio/gpio.h is the right source of these
> > defines for everyone - including non-OF systems. I would prefer the
> > ones in include/linux/gpio/machine.h be the upstream source but then
> > headers in include/dt-bindings/ cannot include them so my second-best
> > suggestion is to rename the ones in include/linux/gpio/machine.h and
> > treewide too. In general values from ./dt-bindings/gpio/gpio.h should
> > only be used in DTS sources and gpiolib-of code.
>
> Then, please fix that your way. It's quite annoying issue.
>

This is not difficult in itself but it's a tree-wide change so we will
probably have to send it to Torvalds at the end of the merge window in
a separate pull-request.

I don't really have time now, I'll be travelling for 5 weeks in a row.
I'll see closer to the merge window. Or next release cycle.

Bart
Andy Shevchenko April 9, 2024, 1:30 p.m. UTC | #4
On Tue, Apr 09, 2024 at 02:55:20PM +0200, Bartosz Golaszewski wrote:
> On Tue, Apr 9, 2024 at 2:51 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Tue, Apr 09, 2024 at 11:42:37AM +0200, Bartosz Golaszewski wrote:
> > > On Tue, Apr 9, 2024 at 1:17 AM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > >
> > > > The GPIO_* flag definitions are *almost* duplicated in two files
> > > > (with unmatches OPEN_SOURCE / OPEN_DRAIN). Moreover, some code relies
> > > > on one set of definitions while the rest is on the other. Clean up
> > > > this mess by providing only one source of the definitions to all.
> > > >
> > > > Fixes: b424808115cb ("brcm80211: brcmsmac: Move LEDs to GPIO descriptors")
> > > > Fixes: 5923ea6c2ce6 ("gpio: pass lookup and descriptor flags to request_own")
> > > > Fixes: fed7026adc7c ("gpiolib: Make use of enum gpio_lookup_flags consistent")
> > > > Fixes: 4c0facddb7d8 ("gpio: core: Decouple open drain/source flag with active low/high")
> > > > Fixes: 69d301fdd196 ("gpio: add DT bindings for existing consumer flags")
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > > ---
> > > >  drivers/gpio/gpiolib-of.c                     |  5 ++---
> > > >  drivers/gpio/gpiolib.c                        |  8 +++-----
> > > >  .../broadcom/brcm80211/brcmsmac/led.c         |  2 +-
> > > >  include/linux/gpio/driver.h                   |  3 +--
> > > >  include/linux/gpio/machine.h                  | 20 +++++--------------
> > > >  5 files changed, 12 insertions(+), 26 deletions(-)
> > >
> > > I don't think ./dt-bindings/gpio/gpio.h is the right source of these
> > > defines for everyone - including non-OF systems. I would prefer the
> > > ones in include/linux/gpio/machine.h be the upstream source but then
> > > headers in include/dt-bindings/ cannot include them so my second-best
> > > suggestion is to rename the ones in include/linux/gpio/machine.h and
> > > treewide too. In general values from ./dt-bindings/gpio/gpio.h should
> > > only be used in DTS sources and gpiolib-of code.
> >
> > Then, please fix that your way. It's quite annoying issue.
> 
> This is not difficult in itself

I'm not sure, what about enum gpio_lookup_flags? Shall we resurrect it?
I see that you have better vision anyway. Consider my patch as a problem
report (and as bonus you have already list of Fixes tags :-).

> but it's a tree-wide change so we will
> probably have to send it to Torvalds at the end of the merge window in
> a separate pull-request.

WFM!

> I don't really have time now, I'll be travelling for 5 weeks in a row.
> I'll see closer to the merge window. Or next release cycle.

But can you prioritize this? It's a carefully planted minefield with already
a bug and confusion here.