linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Arnd Bergmann <arnd@arndb.de>,
	Alexandre Courbot <gnurou@gmail.com>,
	Alexandre Courbot <acourbot@nvidia.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>,
	Jonathan Corbet <corbet@lwn.net>,
	Russell King <linux@armlinux.org.uk>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	"open list:GENERIC INCLUDE/ASM HEADER FILES" 
	<linux-arch@vger.kernel.org>
Subject: Re: [PATCH] gpio: Allow user to customise maximum number of GPIOs
Date: Thu, 18 Aug 2022 14:25:39 +0200	[thread overview]
Message-ID: <CACRpkda0+iy8H0YmyowSDn8RbYgnVbC1k+o5F67inXg4Qb934Q@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a0j-54_OkXC7x3NSNaHhwJ+9umNgbpsrPxUB4dwewK63A@mail.gmail.com>

On Thu, Aug 18, 2022 at 1:33 PM Arnd Bergmann <arnd@arndb.de> wrote:
> On Thu, Aug 18, 2022 at 1:13 PM Linus Walleij <linus.walleij@linaro.org> wrote:

> > static inline bool gpio_is_valid(int number)
> > {
> >         return number >= 0 && number < ARCH_NR_GPIOS;
> > }
> >
> > ?
> >
> > If using GPIO descriptors, any descriptor != NULL is valid,
> > this one is just used with legacy GPIOs. Maybe we should just
> > delete gpio_is_valid() everywhere and then drop the cap?
>
> I think it makes sense to keep gpio_is_valid() for as long as we
> support the numbers.

Hmmm....

> > I think there may be systems and users that still depend on GPIO base
> > numbers being assigned from ARCH_NR_GPIOS and
> > downwards (userspace GPIO numbers in sysfs will also change...)
> > otherwise we could assign from 0 and up.
>
> Is it possible to find in-kernel users that depend on well-known
> numbers for dynamically assigned gpios? I would argue
> that those are always broken.

Most in-kernel users hard-code the base to something like
0 etc it's only the ones that code -1 into .base that are in
trouble because that will activate dynamic assignment for the
base.

git grep 'base = -1' yields these suspects:

arch/arm/common/sa1111.c:       sachip->gc.base = -1;
arch/arm/common/scoop.c:        devptr->gpio.base = -1;
arch/powerpc/platforms/52xx/mpc52xx_gpt.c:      gpt->gc.base = -1;
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c: gc->base = -1;

That's all! We could just calculate these to 512-ngpios and
hardcode that instead.

> Even for the sysfs interface, it is questionable to rely on
> specific numbers because at least in an arm multiplatform
> kernel the top number changes based on kernel configuration.

Yeah :/ still these users tend to angrily report any breakage
due to expected (fragile) behaviour.

> > Right now the safest would be:
> > Assign from 512 and downwards until we hit 0 then assign
> > from something high, like U32_MAX and downward.
> >
> > That requires dropping gpio_is_valid() everywhere.
> >
> > If we wanna be bold, just delete gpio_is_valid() and assign
> > bases from 0 and see what happens. But I think that will
> > lead to regressions.
>
> I'm still unsure how removing gpio_is_valid() would help.

If we allow GPIO base all the way to U32_MAX
this function becomes:

static inline bool gpio_is_valid(int number)
{
        return number >= 0 && number < U32_MAX;
}

and we can then just

#define gpio_is_valid true

and in that case it is better to delete the use of this function
altogether since it can not fail.

> What I could imagine as a next step would be to mark all
> consumer drivers and the sysfs interface that use gpio
> numbers as 'depends on GPIO_LEGACY' and then only
> provide the corresponding drivers if that option is set.

Hm I wonder what Bartosz and Alexandre Courbot and thinks
about a GPIO_LEGACY symbol to phase out the global
GPIO numberspace. I kind of like the idea.

I made the sysfs depend on CONFIG_EXPERT to at least make it less
accessible and not provide users with guns to shoot themselves
in the foot.

Yours,
Linus Walleij

  reply	other threads:[~2022-08-18 12:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 10:40 [PATCH] gpio: Allow user to customise maximum number of GPIOs Christophe Leroy
2022-08-11 19:57 ` H. Peter Anvin
2022-08-12 21:58   ` Andy Shevchenko
2022-08-12 23:21     ` H. Peter Anvin
2022-08-17 17:21   ` Christophe Leroy
2022-08-17 17:46 ` Arnd Bergmann
2022-08-18  6:00   ` Christophe Leroy
2022-08-18  8:25     ` Arnd Bergmann
2022-08-18  9:33 ` Linus Walleij
2022-08-18  9:47   ` Arnd Bergmann
2022-08-18 11:13     ` Linus Walleij
2022-08-18 11:33       ` Arnd Bergmann
2022-08-18 12:25         ` Linus Walleij [this message]
2022-08-18 12:46           ` Arnd Bergmann
2022-08-18 13:11             ` Christophe Leroy
2022-08-25 13:36             ` Linus Walleij
2022-08-25 14:00               ` Christophe Leroy
2022-08-26 13:49                 ` Linus Walleij
2022-08-26 15:08                   ` Christophe Leroy
2022-08-26 21:54                     ` Linus Walleij
2022-08-28  9:06                       ` Christophe Leroy
2022-08-28 10:04                         ` Arnd Bergmann
2022-08-30  7:58                           ` Davide Ciminaghi
2022-08-31 13:32                             ` Linus Walleij
2022-08-31 14:12                               ` Davide Ciminaghi
2022-08-31 21:07                                 ` Andy Shevchenko
2022-08-31 21:48                                   ` Davide Ciminaghi
2022-08-30  8:33                           ` Alessandro Rubini
2022-08-30  9:03                             ` Christophe Leroy
2022-08-28 11:35                         ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACRpkda0+iy8H0YmyowSDn8RbYgnVbC1k+o5F67inXg4Qb934Q@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=acourbot@nvidia.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=brgl@bgdev.pl \
    --cc=christophe.leroy@csgroup.eu \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=gnurou@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).