* [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show()
@ 2024-04-25 13:58 Léo DUBOIN
2024-04-25 13:58 ` [PATCH 1/2] pinctrl: core: take into account the pins array " Léo DUBOIN
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Léo DUBOIN @ 2024-04-25 13:58 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
This series covers errors I encountered with the pinctrl_pins_show()
function when dealing with named gpio ranges generated through the
device tree using 'gpio-ranges-group-names'.
These errors were introduced with the original implementation in
f1b206cf7c57561ea156798f323b0541a783bd2f.
Léo DUBOIN (2):
pinctrl: core: take into account the pins array in pinctrl_pins_show()
pinctrl: core: reset gpio_device in loop in pinctrl_pins_show()
drivers/pinctrl/core.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
--
2.42.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] pinctrl: core: take into account the pins array in pinctrl_pins_show()
2024-04-25 13:58 [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show() Léo DUBOIN
@ 2024-04-25 13:58 ` Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND " Léo DUBOIN
2024-04-25 13:58 ` [PATCH 2/2] pinctrl: core: reset gpio_device in loop " Léo DUBOIN
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Léo DUBOIN @ 2024-04-25 13:58 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
We previously only looked at the 'pin_base' of the pinctrl_gpio_ranges
struct for determining if a pin matched a GPIO number.
This value is present only if the 'pins' array is not NULL,
and is 0 otherwise. This means that GPIO ranges declared using
gpiochip_add_pingroup_range(), thus making use of pins, were always matched
by the pins in the range [0-npins] even if they contained pins in a
completely separate range.
Signed-off-by: Léo DUBOIN <lduboin@freebox.fr>
---
drivers/pinctrl/core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 6649357637ff..901f2f9bf850 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1672,11 +1672,20 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
#ifdef CONFIG_GPIOLIB
gpio_num = -1;
list_for_each_entry(range, &pctldev->gpio_ranges, node) {
- if ((pin >= range->pin_base) &&
- (pin < (range->pin_base + range->npins))) {
- gpio_num = range->base + (pin - range->pin_base);
- break;
+ if (range->pins != NULL) {
+ for (int i = 0; i < range->npins; ++i) {
+ if (range->pins[i] == pin) {
+ gpio_num = range->base + i;
+ break;
+ }
+ }
+ } else if ((pin >= range->pin_base) &&
+ (pin < (range->pin_base + range->npins))) {
+ gpio_num =
+ range->base + (pin - range->pin_base);
}
+ if (gpio_num != -1)
+ break;
}
if (gpio_num >= 0)
/*
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] pinctrl: core: reset gpio_device in loop in pinctrl_pins_show()
2024-04-25 13:58 [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show() Léo DUBOIN
2024-04-25 13:58 ` [PATCH 1/2] pinctrl: core: take into account the pins array " Léo DUBOIN
@ 2024-04-25 13:58 ` Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND " Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND 0/2] pinctrl: core: fix untreated named gpio ranges " Léo DUBOIN
2024-05-27 13:43 ` Linus Walleij
3 siblings, 1 reply; 7+ messages in thread
From: Léo DUBOIN @ 2024-04-25 13:58 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
We were not resetting the pointer to the associated gpio_device once
we are done displaying a pin's information.
This meant that once we reached the end of a gpio-range, if there
were pins right after it that did not belong to any known range,
they would be associated with the previous range's gpio device.
This resulted in those pins appearing as <4294966783:old_gdev> instead
of the expected <0:?> (due to gpio_num being -1).
Signed-off-by: Léo DUBOIN <lduboin@freebox.fr>
---
drivers/pinctrl/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 901f2f9bf850..ad878196ada9 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1670,6 +1670,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
seq_printf(s, "pin %d (%s) ", pin, desc->name);
#ifdef CONFIG_GPIOLIB
+ gdev = NULL;
gpio_num = -1;
list_for_each_entry(range, &pctldev->gpio_ranges, node) {
if (range->pins != NULL) {
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH RESEND 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show()
2024-04-25 13:58 [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show() Léo DUBOIN
2024-04-25 13:58 ` [PATCH 1/2] pinctrl: core: take into account the pins array " Léo DUBOIN
2024-04-25 13:58 ` [PATCH 2/2] pinctrl: core: reset gpio_device in loop " Léo DUBOIN
@ 2024-05-10 16:25 ` Léo DUBOIN
2024-05-27 13:43 ` Linus Walleij
3 siblings, 0 replies; 7+ messages in thread
From: Léo DUBOIN @ 2024-05-10 16:25 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
This series covers errors I encountered with the pinctrl_pins_show()
function when dealing with named gpio ranges generated through the
device tree using 'gpio-ranges-group-names'.
These errors were introduced with the original implementation in
f1b206cf7c57561ea156798f323b0541a783bd2f.
Léo DUBOIN (2):
pinctrl: core: take into account the pins array in pinctrl_pins_show()
pinctrl: core: reset gpio_device in loop in pinctrl_pins_show()
drivers/pinctrl/core.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
--
2.42.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RESEND 1/2] pinctrl: core: take into account the pins array in pinctrl_pins_show()
2024-04-25 13:58 ` [PATCH 1/2] pinctrl: core: take into account the pins array " Léo DUBOIN
@ 2024-05-10 16:25 ` Léo DUBOIN
0 siblings, 0 replies; 7+ messages in thread
From: Léo DUBOIN @ 2024-05-10 16:25 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
We previously only looked at the 'pin_base' of the pinctrl_gpio_ranges
struct for determining if a pin matched a GPIO number.
This value is present only if the 'pins' array is not NULL,
and is 0 otherwise. This means that GPIO ranges declared using
gpiochip_add_pingroup_range(), thus making use of pins, were always matched
by the pins in the range [0-npins] even if they contained pins in a
completely separate range.
Signed-off-by: Léo DUBOIN <lduboin@freebox.fr>
---
drivers/pinctrl/core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 6649357637ff..901f2f9bf850 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1672,11 +1672,20 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
#ifdef CONFIG_GPIOLIB
gpio_num = -1;
list_for_each_entry(range, &pctldev->gpio_ranges, node) {
- if ((pin >= range->pin_base) &&
- (pin < (range->pin_base + range->npins))) {
- gpio_num = range->base + (pin - range->pin_base);
- break;
+ if (range->pins != NULL) {
+ for (int i = 0; i < range->npins; ++i) {
+ if (range->pins[i] == pin) {
+ gpio_num = range->base + i;
+ break;
+ }
+ }
+ } else if ((pin >= range->pin_base) &&
+ (pin < (range->pin_base + range->npins))) {
+ gpio_num =
+ range->base + (pin - range->pin_base);
}
+ if (gpio_num != -1)
+ break;
}
if (gpio_num >= 0)
/*
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH RESEND 2/2] pinctrl: core: reset gpio_device in loop in pinctrl_pins_show()
2024-04-25 13:58 ` [PATCH 2/2] pinctrl: core: reset gpio_device in loop " Léo DUBOIN
@ 2024-05-10 16:25 ` Léo DUBOIN
0 siblings, 0 replies; 7+ messages in thread
From: Léo DUBOIN @ 2024-05-10 16:25 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-kernel, Léo DUBOIN
We were not resetting the pointer to the associated gpio_device once
we are done displaying a pin's information.
This meant that once we reached the end of a gpio-range, if there
were pins right after it that did not belong to any known range,
they would be associated with the previous range's gpio device.
This resulted in those pins appearing as <4294966783:old_gdev> instead
of the expected <0:?> (due to gpio_num being -1).
Signed-off-by: Léo DUBOIN <lduboin@freebox.fr>
---
drivers/pinctrl/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 901f2f9bf850..ad878196ada9 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1670,6 +1670,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
seq_printf(s, "pin %d (%s) ", pin, desc->name);
#ifdef CONFIG_GPIOLIB
+ gdev = NULL;
gpio_num = -1;
list_for_each_entry(range, &pctldev->gpio_ranges, node) {
if (range->pins != NULL) {
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH RESEND 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show()
2024-04-25 13:58 [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show() Léo DUBOIN
` (2 preceding siblings ...)
2024-05-10 16:25 ` [PATCH RESEND 0/2] pinctrl: core: fix untreated named gpio ranges " Léo DUBOIN
@ 2024-05-27 13:43 ` Linus Walleij
3 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2024-05-27 13:43 UTC (permalink / raw)
To: Léo DUBOIN; +Cc: linux-gpio, linux-kernel
On Fri, May 10, 2024 at 6:26 PM Léo DUBOIN <lduboin@freebox.fr> wrote:
> This series covers errors I encountered with the pinctrl_pins_show()
> function when dealing with named gpio ranges generated through the
> device tree using 'gpio-ranges-group-names'.
>
> These errors were introduced with the original implementation in
> f1b206cf7c57561ea156798f323b0541a783bd2f.
>
> Léo DUBOIN (2):
> pinctrl: core: take into account the pins array in pinctrl_pins_show()
> pinctrl: core: reset gpio_device in loop in pinctrl_pins_show()
Patches applied for kernel v6.11.
It's debugfs so per definition no regression, people get to test it
in linux-next.
Thanks for looking into this!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-27 13:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-25 13:58 [PATCH 0/2] pinctrl: core: fix untreated named gpio ranges in pinctrl_pins_show() Léo DUBOIN
2024-04-25 13:58 ` [PATCH 1/2] pinctrl: core: take into account the pins array " Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND " Léo DUBOIN
2024-04-25 13:58 ` [PATCH 2/2] pinctrl: core: reset gpio_device in loop " Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND " Léo DUBOIN
2024-05-10 16:25 ` [PATCH RESEND 0/2] pinctrl: core: fix untreated named gpio ranges " Léo DUBOIN
2024-05-27 13:43 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).