printf: fix errname.c list
authorArnd Bergmann <arnd@arndb.de>
Mon, 6 Feb 2023 19:40:57 +0000 (20:40 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:33:27 +0000 (09:33 +0100)
[ Upstream commit 0c2baf6509af1d11310ae4c1c839481a6e9a4bc4 ]

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 <pmladek@suse.com>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/all/20210514213456.745039-1-arnd@kernel.org/
Link: https://lore.kernel.org/all/20210927123409.1109737-1-arnd@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20230206194126.380350-1-arnd@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
lib/errname.c

index 05cbf73..67739b1 100644 (file)
@@ -21,6 +21,7 @@ static const char *names_0[] = {
        E(EADDRNOTAVAIL),
        E(EADV),
        E(EAFNOSUPPORT),
+       E(EAGAIN), /* EWOULDBLOCK */
        E(EALREADY),
        E(EBADE),
        E(EBADF),
@@ -31,15 +32,17 @@ static const char *names_0[] = {
        E(EBADSLT),
        E(EBFONT),
        E(EBUSY),
-#ifdef ECANCELLED
-       E(ECANCELLED),
-#endif
+       E(ECANCELED), /* ECANCELLED */
        E(ECHILD),
        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 +169,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),