Re: [PATCH] printf: fix Woverride-init warning for EDEADLK errno

From: Uwe Kleine-König
Date: Tue Oct 27 2020 - 02:56:05 EST


Good morning Arnd,

On 10/26/20 10:49 PM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> 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 */
> | ^
> lib/errname.c:15:67: note: (near initialization for 'names_0[35]')
> 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 */
> | ^

bad performance of gcc to warn twice about the same line and not
mentioning the line that has E(EDEADLOCK).

> Make that line conditional on the two values being distinct.
>
> Fixes: 57f5677e535b ("printf: add support for printing symbolic error names")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> lib/errname.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/lib/errname.c b/lib/errname.c
> index 0c4d3e66170e..6adff0bf2445 100644
> --- a/lib/errname.c
> +++ b/lib/errname.c
> @@ -169,7 +169,9 @@ static const char *names_0[] = {
> E(ECANCELED), /* ECANCELLED */
> E(EAGAIN), /* EWOULDBLOCK */
> E(ECONNREFUSED), /* EREFUSED */
> +#if EDEADLK != EDEADLOCK
> E(EDEADLK), /* EDEADLOCK */
> +#endif

The comments suggest that duplicates are expected. Would it make sense
to add similar conditions to the other three entries?

Best regards
Uwe

> };
> #undef E
>


Attachment: signature.asc
Description: OpenPGP digital signature