Skip to contentSkip to conversation

pinctrl: bcm2835: don't -EINVAL on alternate funcs from get_direction()

PATCH In review Bartosz Golaszewski 5 participants 8 messages Feb 19, 2025 – Mar 4, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: bcm2835: don't -EINVAL on alternate funcs from get_direction()

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

Fixes 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pinctrl/bcm/pinctrl-bcm2835.c +7 -7
index cc1fe0555e19..eaeec096bc9a 100644
@@ -346,14 +346,14 @@ static int bcm2835_gpio_get_direction(struct gpio_chip *chip, unsigned int offse
 	struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
 	enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset);
 
-	/* Alternative function doesn't clearly provide a direction */
-	if (fsel > BCM2835_FSEL_GPIO_OUT)
-		return -EINVAL;
+	if (fsel == BCM2835_FSEL_GPIO_OUT)
+		return GPIO_LINE_DIRECTION_OUT;
 
-	if (fsel == BCM2835_FSEL_GPIO_IN)
-		return GPIO_LINE_DIRECTION_IN;
-
-	return GPIO_LINE_DIRECTION_OUT;
+	/*
+	 * Alternative function doesn't clearly provide a direction. Default
+	 * to INPUT.
+	 */
+	return GPIO_LINE_DIRECTION_IN;
 }
 
 static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
Signature · 1 line
2.45.2
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

Quoted 4 lines
Fixes 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")

Closes:
https://lore.kernel.org/all/[email protected]/

Quoted 20 lines
---
  drivers/pinctrl/bcm/pinctrl-bcm2835.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pinctrl/bcm/pinctrl-bcm2835.c +2 -5
index cc1fe0555e19..eaeec096bc9a 100644
@@ -346,14 +346,14 @@ static int bcm2835_gpio_get_direction(struct gpio_chip *chip, unsigned int offse
  	struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
  	enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset);
 
-	/* Alternative function doesn't clearly provide a direction */
-	if (fsel > BCM2835_FSEL_GPIO_OUT)
-		return -EINVAL;
+	if (fsel == BCM2835_FSEL_GPIO_OUT)
+		return GPIO_LINE_DIRECTION_OUT;
 
-	if (fsel == BCM2835_FSEL_GPIO_IN)
-		return GPIO_LINE_DIRECTION_IN;

drivers/pinctrl/bcm/pinctrl-bcm2835.c static int bcm2835_gpio_get_direction(struct gpio_chip *chip, unsigned int offse · line 359

Quoted 10 lines
drivers/pinctrl/bcm/pinctrl-bcm2835.c +5 -2
-
-	return GPIO_LINE_DIRECTION_OUT;
+	/*
+	 * Alternative function doesn't clearly provide a direction. Default
+	 * to INPUT.
+	 */
+	return GPIO_LINE_DIRECTION_IN;
  }
 
  static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value)

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#2 lore raw
In reply to Bartosz Golaszewski
Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

I see this was already tested for these specific boards. I've also found that Avenger96 is failing with bisect pointing to the same commit this is fixing:

    https://lava.sirena.org.uk/scheduler/job/1126314

as is the Libretech Potato:

    https://lava.sirena.org.uk/scheduler/job/1126285

neither of which produce any output before dying, they'll not be fixed by this change. Seems like an audit of the drivers might be in order?

#3 lore raw
Quoted 17 lines · Mark Brown
Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

I see this was already tested for these specific boards. I've also found that Avenger96 is failing with bisect pointing to the same commit this is fixing:

Quoted 8 lines
    https://lava.sirena.org.uk/scheduler/job/1126314

as is the Libretech Potato:

    https://lava.sirena.org.uk/scheduler/job/1126285

neither of which produce any output before dying, they'll not be fixed by this change. Seems like an audit of the drivers might be in order?

Right. I don't know if they return EINVAL or some other error so let me prepare a change that will not bail-out but simply warn on get_direction() errors in gpiochip_add_data() instead.

This patch can still go upstream IMO.

Bart

Reviewed-by on v1 1/1
#6 lore raw
In reply to Bartosz Golaszewski

Am 19.02.25 um 11:27 schrieb Bartosz Golaszewski:

Quoted 11 lines

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

Quoted 4 lines
Fixes 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")

Thanks

#4 lore raw
In reply to Bartosz Golaszewski
Quoted 24 lines · Bartosz Golaszewski
Quoted 23 lines · Mark Brown
Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

I see this was already tested for these specific boards. I've also found that Avenger96 is failing with bisect pointing to the same commit this is fixing:

    https://lava.sirena.org.uk/scheduler/job/1126314

as is the Libretech Potato:

    https://lava.sirena.org.uk/scheduler/job/1126285
Quoted 8 lines
Quoted 2 lines

neither of which produce any output before dying, they'll not be fixed by this change. Seems like an audit of the drivers might be in order?

Right. I don't know if they return EINVAL or some other error so let me prepare a change that will not bail-out but simply warn on get_direction() errors in gpiochip_add_data() instead.

This patch can still go upstream IMO.

I'm fine to apply it, maybe as non-urgent fix at this point? (for -next)

Do you want to send a non-RFC/RFT version or should I just apply it?

Yours,
Linus Walleij

#5 lore raw
Quoted 29 lines · Linus Walleij
Quoted 27 lines · Bartosz Golaszewski
Quoted 25 lines · Mark Brown
Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

I see this was already tested for these specific boards. I've also found that Avenger96 is failing with bisect pointing to the same commit this is fixing:

    https://lava.sirena.org.uk/scheduler/job/1126314

as is the Libretech Potato:

    https://lava.sirena.org.uk/scheduler/job/1126285

neither of which produce any output before dying, they'll not be fixed by this change. Seems like an audit of the drivers might be in order?

Quoted 8 lines
Quoted 5 lines

Right. I don't know if they return EINVAL or some other error so let me prepare a change that will not bail-out but simply warn on get_direction() errors in gpiochip_add_data() instead.

This patch can still go upstream IMO.

I'm fine to apply it, maybe as non-urgent fix at this point? (for -next)

Yes, the offending changes in gpiolib.c were dropped so this can go in the non-urgent way.

Quoted 2 lines

Do you want to send a non-RFC/RFT version or should I just apply it?

You can take it as is. It got tested and reviewed, so the tags served their purpose. :)

Bart

#7 lore raw
In reply to Bartosz Golaszewski
Quoted 11 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Since commit 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()") we check the return value of the get_direction() callback as per its API contract. This driver returns -EINVAL if the pin in question is set to one of the alternative (non-GPIO) functions. This isn't really an error that should be communicated to GPIOLIB so default to returning the "safe" value of INPUT in this case. The GPIO subsystem does not have the notion of "unknown" direction.

Quoted 4 lines
Fixes 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")

Patch applied!

Yours,
Linus Walleij