Skip to contentSkip to conversation

pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

PATCH In review Jonas Karlman 3 participants 3 messages May 10, 2024 – May 18, 2024 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the format of the gpio-ranges prop as:

The format is: <[pin controller phandle], [GPIO controller offset],

                  [pin controller offset], [number of pins]>;

Example:

      gpio-ranges = <&foo 0 20 10>, <&bar 10 50 20>;

This means:
- pins 20..29 on pin controller "foo" is mapped to GPIO line 0..9 and
- pins 50..69 on pin controller "bar" is mapped to GPIO line 10..29

For this example, a call to pinctrl_gpio_get_pinctrl_and_offset() using offset 10 incorrectly return pin controller "foo" instead of "bar".

Fix this by using an exclusive range check.

Fixes d0bb00adccb8 ("pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for gpio-ranges array")
---
 drivers/pinctrl/pinctrl-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-uclass.c +1 -1
index 245510a96312..6f10150b2a42 100644
@@ -210,7 +210,7 @@ pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, unsigned offset,
 		pfc_base = args.args[1];
 		pfc_pins = args.args[2];
 
-		if (offset >= gpio_offset && offset <= gpio_offset + pfc_pins)
+		if (offset >= gpio_offset && offset < gpio_offset + pfc_pins)
 			break;
 	}
 
Signature · 1 line
2.43.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jonas Karlman

Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the format of the gpio-ranges prop as:

The format is: <[pin controller phandle], [GPIO controller offset],

                   [pin controller offset], [number of pins]>;

Example:

       gpio-ranges = <&foo 0 20 10>, <&bar 10 50 20>;

This means:
- pins 20..29 on pin controller "foo" is mapped to GPIO line 0..9 and
- pins 50..69 on pin controller "bar" is mapped to GPIO line 10..29

Quoted 7 lines

For this example, a call to pinctrl_gpio_get_pinctrl_and_offset() using offset 10 incorrectly return pin controller "foo" instead of "bar".

Fix this by using an exclusive range check.

Fixes d0bb00adccb8 ("pinctrl: fix pinctrl_gpio_get_pinctrl_and_offset for gpio-ranges array")

Thanks for your patch.

Quoted 17 lines
---
  drivers/pinctrl/pinctrl-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-uclass.c +1 -1
index 245510a96312..6f10150b2a42 100644
@@ -210,7 +210,7 @@ pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, unsigned offset,
  		pfc_base = args.args[1];
  		pfc_pins = args.args[2];
 
-		if (offset >= gpio_offset && offset <= gpio_offset + pfc_pins)
+		if (offset >= gpio_offset && offset < gpio_offset + pfc_pins)
  			break;
  	}
 
#2 lore raw
In reply to Jonas Karlman
Quoted 9 lines · Jonas Karlman

Linux kernel Documentation/devicetree/bindings/gpio/gpio.txt define the format of the gpio-ranges prop as:

The format is: <[pin controller phandle], [GPIO controller offset],

                  [pin controller offset], [number of pins]>;

Example:

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom