On Thu, Aug 18, 2022 at 2:46 PM Arnd Bergmann <arnd@xxxxxxxx> wrote: > On Thu, Aug 18, 2022 at 2:25 PM Linus Walleij <linus.walleij@xxxxxxxxxx> wrote: > > 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. > > How do the consumers find the numbers for these four? For SA1111 the chip gets named "sa1111" and some consumers actually use proper machine descriptions, maybe all? arch/arm/mach-sa1100/jornada720.c: GPIO_LOOKUP("sa1111", 0, "s0-power", GPIO_ACTIVE_HIGH), arch/arm/mach-sa1100/jornada720.c: GPIO_LOOKUP("sa1111", 1, "s1-power", GPIO_ACTIVE_HIGH), (...) For Scoop it is conditionally overridden in the code. I guess always overridden. For powerpc these seem to be using (old but working) device tree lookups, so should not be an issue. Sadly I'm not 100% sure that there are no random hard-coded GPIO numbers referring to whatever the framework gave them at the time the code was written :( Another reason the base is assigned from above (usually from 512 and downward) is that the primary SoC GPIO usually want to be at base 0 and there is no guarantee that it will get probed first. So hard-coded GPIO bases go from 0 -> n and dynamically allocateed GPIO bases from n <- 512. Then we hope they don't meet and overlap in the middle... > > and in that case it is better to delete the use of this function > > altogether since it can not fail. > > S32_MAX might be a better upper bound. That allows to > just have no number assigned to a gpio chip. Any driver > code calling desc_to_gpio() could then get back -1 > or a negative error code. > > Making the ones that are invalid today valid sounds like > a step backwards to me if the goal is to stop using > gpio numbers and most consumers no longer need them. OK I get it... Now: who wants to write this patch? :) Christophe? Will you take a stab at it? Yours, Linus Walleij