Skip to contentSkip to conversation

gpioinfo: mark kernel claimed lines as used

PATCH Superseded Ramon Fried 2 participants 4 messages Jul 30, 2019 – Jul 31, 2019 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpioinfo: mark kernel claimed lines as used

In case where the GPIOLINE_FLAG_KERNEL flag was set because of muxing, The used column was still showing the pin as "unused"
Fix that by writing "used".

---
 tools/gpioinfo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/gpioinfo.c +5 -2
index bb17262..85f8758 100644
@@ -119,8 +119,11 @@ static void list_lines(struct gpiod_chip *chip)
 		     : prinfo(&of, 12, "unnamed");
 		printf(" ");
 
-		consumer ? prinfo(&of, 12, "\"%s\"", consumer)
-			 : prinfo(&of, 12, "unused");
+		if (gpiod_line_is_used(line) && !consumer)
+			prinfo(&of, 12, "used");
+		else
+			consumer ? prinfo(&of, 12, "\"%s\"", consumer)
+				 : prinfo(&of, 12, "unused");
 		printf(" ");
 
 		prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
Signature · 1 line
2.22.0
#1 lore raw

wt., 30 lip 2019 o 21:04 Ramon Fried <[email protected]> napisał(a):

Quoted 29 lines

In case where the GPIOLINE_FLAG_KERNEL flag was set because of muxing, The used column was still showing the pin as "unused"
Fix that by writing "used".

---
 tools/gpioinfo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/gpioinfo.c +5 -3
index bb17262..85f8758 100644
@@ -119,8 +119,11 @@ static void list_lines(struct gpiod_chip *chip)
                     : prinfo(&of, 12, "unnamed");
                printf(" ");
 
-               consumer ? prinfo(&of, 12, "\"%s\"", consumer)
-                        : prinfo(&of, 12, "unused");
+               if (gpiod_line_is_used(line) && !consumer)
+                       prinfo(&of, 12, "used");
+               else
+                       consumer ? prinfo(&of, 12, "\"%s\"", consumer)
+                                : prinfo(&of, 12, "unused");
                printf(" ");
 
                prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
--
Quoted 2 lines

2.22.0

Good catch! I think we can make it even more readable by first calling gpiod_line_is_used() and printing 'unused' if it returns false and then checking the consumer string.

Bart

#2 lore raw
Quoted 29 lines · Bartosz Golaszewski

wt., 30 lip 2019 o 21:04 Ramon Fried <[email protected]> napisał(a):

Quoted 27 lines

In case where the GPIOLINE_FLAG_KERNEL flag was set because of muxing, The used column was still showing the pin as "unused"
Fix that by writing "used".

---
 tools/gpioinfo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/gpioinfo.c +5 -2
index bb17262..85f8758 100644
@@ -119,8 +119,11 @@ static void list_lines(struct gpiod_chip *chip)
                     : prinfo(&of, 12, "unnamed");
                printf(" ");
 
-               consumer ? prinfo(&of, 12, "\"%s\"", consumer)
-                        : prinfo(&of, 12, "unused");
+               if (gpiod_line_is_used(line) && !consumer)
+                       prinfo(&of, 12, "used");
+               else
+                       consumer ? prinfo(&of, 12, "\"%s\"", consumer)
+                                : prinfo(&of, 12, "unused");
                printf(" ");
 
Quoted 8 lines
Quoted 4 lines
tools/gpioinfo.c +0 -1
                prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
--

2.22.0

Good catch! I think we can make it even more readable by first calling gpiod_line_is_used() and printing 'unused' if it returns false and then checking the consumer string.

OK, I'll send v2.
Thanks,
Ramon.

Quoted 2 lines

Bart

#3 lore raw

śr., 31 lip 2019 o 09:48 Ramon Fried <[email protected]> napisał(a):

Quoted 40 lines
Quoted 29 lines · Bartosz Golaszewski

wt., 30 lip 2019 o 21:04 Ramon Fried <[email protected]> napisał(a):

Quoted 27 lines

In case where the GPIOLINE_FLAG_KERNEL flag was set because of muxing, The used column was still showing the pin as "unused"
Fix that by writing "used".

---
 tools/gpioinfo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/gpioinfo.c +5 -2
index bb17262..85f8758 100644
@@ -119,8 +119,11 @@ static void list_lines(struct gpiod_chip *chip)
                     : prinfo(&of, 12, "unnamed");
                printf(" ");
 
-               consumer ? prinfo(&of, 12, "\"%s\"", consumer)
-                        : prinfo(&of, 12, "unused");
+               if (gpiod_line_is_used(line) && !consumer)
+                       prinfo(&of, 12, "used");
+               else
+                       consumer ? prinfo(&of, 12, "\"%s\"", consumer)
+                                : prinfo(&of, 12, "unused");
                printf(" ");
 
Quoted 8 lines
Quoted 4 lines
tools/gpioinfo.c +0 -1
                prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
--

2.22.0

Good catch! I think we can make it even more readable by first calling gpiod_line_is_used() and printing 'unused' if it returns false and then checking the consumer string.

Quoted 5 lines

OK, I'll send v2.
Thanks,
Ramon.

Quoted 2 lines

Bart

Cool, I'm also thinking that we need to distinguish somehow regular consumer strings from lines used by kernel. Maybe a string like '[kernel]' instead of 'used' would be nice?

Bart