diff mbox series

pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset()

Message ID 20240510193554.884344-1-jonas@kwiboo.se
State Accepted
Commit 31cf22099bc3243ba2779d55fba0282bbcf29ddf
Delegated to: Tom Rini
Headers show
Series pinctrl: Fix pinctrl_gpio_get_pinctrl_and_offset() | expand

Commit Message

Jonas Karlman May 10, 2024, 7:35 p.m. UTC
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")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 drivers/pinctrl/pinctrl-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Quanyang Wang May 11, 2024, 8:58 a.m. UTC | #1
On 5/11/24 03:35, Jonas Karlman wrote:
> 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")
> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>

Thanks for your patch.

Reviewed-by: Quanyang Wang <quanyang.wang@windriver.com>

> ---
>   drivers/pinctrl/pinctrl-uclass.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
> index 245510a96312..6f10150b2a42 100644
> --- a/drivers/pinctrl/pinctrl-uclass.c
> +++ b/drivers/pinctrl/pinctrl-uclass.c
> @@ -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;
>   	}
>
Tom Rini May 18, 2024, 12:08 a.m. UTC | #2
On Fri, 10 May 2024 19:35:51 +0000, Jonas Karlman wrote:

> 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!
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 245510a96312..6f10150b2a42 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -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;
 	}