mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name
@ 2022-01-14  8:47 Ahmad Fatoum
  2022-01-14  8:47 ` [PATCH 2/2] pinctrl: Rockchip: abort GPIO probe gracefully on out-of-range alias id Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-01-14  8:47 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

From: Michael Riesch <michael.riesch@wolfvision.net>

We've so far relied on GPIO controllers being named "gpioX", while the
binding mandates gpio controllers being just called "gpio". This already
broke rk3288 support and rk3568.dtsi upstream also differs from the
version in barebox' arch/arm/dts in that regard.

Instead, do like Linux does and use the alias to match the controllers to
the GPIO banks with a fallback to probe order.

Fixes: 3f2f5980d517 ("dts: update to v5.16-rc1")
Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
[afa: drop strncmp in favor of id comparison, reword commit message]
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 5cf77c58b218..ea748b600419 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -877,18 +877,24 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
 	struct rockchip_pin_bank *bank;
 	char *name;
 	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
+	int gpio = 0;
 
 	match = of_match_node(rockchip_pinctrl_dt_match, node);
 	ctrl = (struct rockchip_pin_ctrl *)match->data;
 
 	for_each_child_of_node(node, np) {
+		int id;
+
 		if (!of_find_property(np, "gpio-controller", NULL))
 			continue;
 
+		id = of_alias_get_id(np, "gpio");
+		if (id < 0)
+			id = gpio++;
+
 		bank = ctrl->pin_banks;
 		for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
-			name = bank->name;
-			if (!strncmp(name, np->name, strlen(name))) {
+			if (bank->bank_num == id) {
 				bank->of_node = np;
 				if (!rockchip_get_bank_data(bank, dev))
 					bank->valid = true;
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] pinctrl: Rockchip: abort GPIO probe gracefully on out-of-range alias id
  2022-01-14  8:47 [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
@ 2022-01-14  8:47 ` Ahmad Fatoum
  2022-01-14  8:49 ` [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
  2022-01-14  9:33 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-01-14  8:47 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

&{/aliases} { gpio120 = &gpio1; } so far led to an out-of-bounds read
when probing &gpio1. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/pinctrl/pinctrl-rockchip.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index ea748b600419..869cce198239 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -334,6 +334,8 @@ static int rockchip_gpio_probe(struct device_d *dev)
 	int ret, bankno;
 
 	bankno = of_alias_get_id(dev->device_node, "gpio");
+	if (bankno >= ctrl->nr_banks)
+		bankno = -EINVAL;
 	if (bankno < 0)
 		return bankno;
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name
  2022-01-14  8:47 [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
  2022-01-14  8:47 ` [PATCH 2/2] pinctrl: Rockchip: abort GPIO probe gracefully on out-of-range alias id Ahmad Fatoum
@ 2022-01-14  8:49 ` Ahmad Fatoum
  2022-01-14  9:33 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2022-01-14  8:49 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On 14.01.22 09:47, Ahmad Fatoum wrote:
> From: Michael Riesch <michael.riesch@wolfvision.net>
> 
> We've so far relied on GPIO controllers being named "gpioX", while the
> binding mandates gpio controllers being just called "gpio". This already
> broke rk3288 support and rk3568.dtsi upstream also differs from the
> version in barebox' arch/arm/dts in that regard.
> 
> Instead, do like Linux does and use the alias to match the controllers to
> the GPIO banks with a fallback to probe order.
> 
> Fixes: 3f2f5980d517 ("dts: update to v5.16-rc1")
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
> [afa: drop strncmp in favor of id comparison, reword commit message]
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

@Sascha, can this go into a master? V7 Rockchip boards should be broken
without this.

> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
> index 5cf77c58b218..ea748b600419 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.c
> +++ b/drivers/pinctrl/pinctrl-rockchip.c
> @@ -877,18 +877,24 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
>  	struct rockchip_pin_bank *bank;
>  	char *name;
>  	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
> +	int gpio = 0;
>  
>  	match = of_match_node(rockchip_pinctrl_dt_match, node);
>  	ctrl = (struct rockchip_pin_ctrl *)match->data;
>  
>  	for_each_child_of_node(node, np) {
> +		int id;
> +
>  		if (!of_find_property(np, "gpio-controller", NULL))
>  			continue;
>  
> +		id = of_alias_get_id(np, "gpio");
> +		if (id < 0)
> +			id = gpio++;
> +
>  		bank = ctrl->pin_banks;
>  		for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
> -			name = bank->name;
> -			if (!strncmp(name, np->name, strlen(name))) {
> +			if (bank->bank_num == id) {
>  				bank->of_node = np;
>  				if (!rockchip_get_bank_data(bank, dev))
>  					bank->valid = true;
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name
  2022-01-14  8:47 [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
  2022-01-14  8:47 ` [PATCH 2/2] pinctrl: Rockchip: abort GPIO probe gracefully on out-of-range alias id Ahmad Fatoum
  2022-01-14  8:49 ` [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
@ 2022-01-14  9:33 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2022-01-14  9:33 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Jan 14, 2022 at 09:47:56AM +0100, Ahmad Fatoum wrote:
> From: Michael Riesch <michael.riesch@wolfvision.net>
> 
> We've so far relied on GPIO controllers being named "gpioX", while the
> binding mandates gpio controllers being just called "gpio". This already
> broke rk3288 support and rk3568.dtsi upstream also differs from the
> version in barebox' arch/arm/dts in that regard.
> 
> Instead, do like Linux does and use the alias to match the controllers to
> the GPIO banks with a fallback to probe order.
> 
> Fixes: 3f2f5980d517 ("dts: update to v5.16-rc1")
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
> [afa: drop strncmp in favor of id comparison, reword commit message]
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Applied to master, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-14  9:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14  8:47 [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
2022-01-14  8:47 ` [PATCH 2/2] pinctrl: Rockchip: abort GPIO probe gracefully on out-of-range alias id Ahmad Fatoum
2022-01-14  8:49 ` [PATCH 1/2] pinctrl: rockchip: use alias rather than full of name Ahmad Fatoum
2022-01-14  9:33 ` Sascha Hauer

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git