Skip to contentSkip to conversation

printf: fix errname.c list

PATCH Superseded Arnd Bergmann 4 participants 5 messages May 14, 2021 – May 17, 2021 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 printf: fix errname.c list

From: Arnd Bergmann <[email protected]>

On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:

lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]
15 | #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~
lib/errname.c:172:2: note: in expansion of macro 'E'

  172 |  E(EDEADLK), /* EDEADLOCK */
      |  ^

On parisc, a similar error happens with -ECANCELLED, which is an alias for ECANCELED.

Make the EDEADLK printing conditional on the number being distinct from EDEADLOCK, and remove the -ECANCELLED bit completely as it can never be hit.

To ensure these are correct, add static_assert lines that verify all the remaining aliases are in fact identical to the canonical name.

Fixes 57f5677e535b ("printf: add support for printing symbolic error names")
Cc Petr Mladek <[email protected]>
---
 lib/errname.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
lib/errname.c +13 -5
index 05cbf731545f..6c5c0aa4de75 100644
@@ -21,6 +21,7 @@ static const char *names_0[] = {
 	E(EADDRNOTAVAIL),
 	E(EADV),
 	E(EAFNOSUPPORT),
+	E(EAGAIN), /* EWOULDBLOCK */
 	E(EALREADY),
 	E(EBADE),
 	E(EBADF),
@@ -38,8 +39,12 @@ static const char *names_0[] = {
 	E(ECHRNG),
 	E(ECOMM),
 	E(ECONNABORTED),
+	E(ECONNREFUSED), /* EREFUSED */
 	E(ECONNRESET),
+	E(EDEADLK), /* EDEADLOCK */
+#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */
 	E(EDEADLOCK),
+#endif
 	E(EDESTADDRREQ),
 	E(EDOM),
 	E(EDOTDOT),
@@ -166,14 +171,17 @@ static const char *names_0[] = {
 	E(EUSERS),
 	E(EXDEV),
 	E(EXFULL),
-
-	E(ECANCELED), /* ECANCELLED */
-	E(EAGAIN), /* EWOULDBLOCK */
-	E(ECONNREFUSED), /* EREFUSED */
-	E(EDEADLK), /* EDEADLOCK */
 };
 #undef E
 
+#ifdef EREFUSED /* parisc */
+static_assert(EREFUSED == ECONNREFUSED);
+#endif
+#ifdef ECANCELLED /* parisc */
+static_assert(ECANCELLED == ECANCELED);
+#endif
+static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
+
 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err
 static const char *names_512[] = {
 	E(ERESTARTSYS),
Signature · 1 line
2.29.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:

lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]
15 | #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
| ^~~
lib/errname.c:172:2: note: in expansion of macro 'E'

  172 |  E(EDEADLK), /* EDEADLOCK */
      |  ^

On parisc, a similar error happens with -ECANCELLED, which is an alias for ECANCELED.

Quoted 7 lines

Make the EDEADLK printing conditional on the number being distinct from EDEADLOCK, and remove the -ECANCELLED bit completely as it can never be hit.

To ensure these are correct, add static_assert lines that verify all the remaining aliases are in fact identical to the canonical name.

Looks good to me, thanks for fixing this.

Quoted 59 lines
Fixes 57f5677e535b ("printf: add support for printing symbolic error names")
Cc Petr Mladek <[email protected]>
---
 lib/errname.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
lib/errname.c +13 -5
index 05cbf731545f..6c5c0aa4de75 100644
@@ -21,6 +21,7 @@ static const char *names_0[] = {
 	E(EADDRNOTAVAIL),
 	E(EADV),
 	E(EAFNOSUPPORT),
+	E(EAGAIN), /* EWOULDBLOCK */
 	E(EALREADY),
 	E(EBADE),
 	E(EBADF),
@@ -38,8 +39,12 @@ static const char *names_0[] = {
 	E(ECHRNG),
 	E(ECOMM),
 	E(ECONNABORTED),
+	E(ECONNREFUSED), /* EREFUSED */
 	E(ECONNRESET),
+	E(EDEADLK), /* EDEADLOCK */
+#if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */
 	E(EDEADLOCK),
+#endif
 	E(EDESTADDRREQ),
 	E(EDOM),
 	E(EDOTDOT),
@@ -166,14 +171,17 @@ static const char *names_0[] = {
 	E(EUSERS),
 	E(EXDEV),
 	E(EXFULL),
-
-	E(ECANCELED), /* ECANCELLED */
-	E(EAGAIN), /* EWOULDBLOCK */
-	E(ECONNREFUSED), /* EREFUSED */
-	E(EDEADLK), /* EDEADLOCK */
 };
 #undef E
 
+#ifdef EREFUSED /* parisc */
+static_assert(EREFUSED == ECONNREFUSED);
+#endif
+#ifdef ECANCELLED /* parisc */
+static_assert(ECANCELLED == ECANCELED);
+#endif
+static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
+
 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err
 static const char *names_512[] = {
 	E(ERESTARTSYS),
Signature · 1 line
2.29.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v2 1/1
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On most architectures, gcc -Wextra warns about the list of error numbers containing both EDEADLK and EDEADLOCK:

lib/errname.c:15:67: warning: initialized field overwritten [-Woverride-init]

    15 | #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
       |                                                                

^~~

Quoted 11 lines

lib/errname.c:172:2: note: in expansion of macro 'E'

   172 |  E(EDEADLK), /* EDEADLOCK */
       |  ^

On parisc, a similar error happens with -ECANCELLED, which is an alias for ECANCELED.

Make the EDEADLK printing conditional on the number being distinct from EDEADLOCK, and remove the -ECANCELLED bit completely as it can never be hit.

Quoted 8 lines

To ensure these are correct, add static_assert lines that verify all the remaining aliases are in fact identical to the canonical name.

Fixes 57f5677e535b ("printf: add support for printing symbolic error names")
Cc Petr Mladek <[email protected]>

LGTM

Thanks
Uwe

#3 lore raw
In reply to Arnd Bergmann

lib/errname.c static const char *names_0[] = {

Quoted 16 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>
from EDEADLOCK, and remove the -ECANCELLED bit completely as it

lib/errname.c +1 -0
index 05cbf731545f..6c5c0aa4de75 100644
@@ -21,6 +21,7 @@ static const char *names_0[] = {
 	E(EADDRNOTAVAIL),
 	E(EADV),
 	E(EAFNOSUPPORT),
+	E(EAGAIN), /* EWOULDBLOCK */
 	E(EALREADY),
 	E(EBADE),
 	E(EBADF),
@@ -38,8 +39,12 @@ static const char *names_0[] = {

somewhere between EBADF and ECHRNG I'd expect a hunk dealing with the ECANCELED stuff

lib/errname.c static const char *names_0[] = { · line 170

Quoted 1 line
lib/errname.c +0 -1
-	E(ECANCELED), /* ECANCELLED */

but I only see this removal?

Otherwise looks good.

Rasmus

#4 lore raw
Quoted 22 lines · Rasmus Villemoes

lib/errname.c static const char *names_0[] = {

Quoted 16 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>
from EDEADLOCK, and remove the -ECANCELLED bit completely as it

lib/errname.c +1 -0
index 05cbf731545f..6c5c0aa4de75 100644
@@ -21,6 +21,7 @@ static const char *names_0[] = {
      E(EADDRNOTAVAIL),
      E(EADV),
      E(EAFNOSUPPORT),
+     E(EAGAIN), /* EWOULDBLOCK */
      E(EALREADY),
      E(EBADE),
      E(EBADF),
@@ -38,8 +39,12 @@ static const char *names_0[] = {

somewhere between EBADF and ECHRNG I'd expect a hunk dealing with the ECANCELED stuff

Quoted 5 lines

lib/errname.c static const char *names_0[] = { · line 170

Quoted 1 line
lib/errname.c +0 -1
-     E(ECANCELED), /* ECANCELLED */

but I only see this removal?

Otherwise looks good.

Fixed now, v3 coming. Thanks!

Arnd