public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: WangYuli <wangyuli@uniontech.com>
Cc: masahiroy@kernel.org, nicolas.schier@linux.dev,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	m.seyfarth@gmail.com, zhanjun@uniontech.com,
	niecheng1@uniontech.com, guanwentao@uniontech.com
Subject: Re: [PATCH] kbuild: Disable -Wdefault-const-init-var-unsafe
Date: Wed, 7 May 2025 20:56:46 +0100	[thread overview]
Message-ID: <20250507195646.GA3495761@ax162> (raw)
In-Reply-To: <7331A23DB8786121+20250507091340.276092-1-wangyuli@uniontech.com>

On Wed, May 07, 2025 at 05:13:40PM +0800, WangYuli wrote:
> Similar to ("kbuild: Disable -Wdefault-const-init-field-unsafe")
> from list, -Wdefault-const-init-var-unsafe need to be disabled too.

Thanks for the change but I already sent a v2 of that change to cover
this warning too:

https://lore.kernel.org/20250506-default-const-init-clang-v2-1-fcfb69703264@kernel.org/

> While I haven't found this warning triggered in the kernel code
> itself (my testing covers just a tiny fraction), it's clearly
> something that should be disabled for the same reason.
> 
> Additionally, because dkms uses kernel compile parameters, some
> out-of-tree modules might also hit this warning, like the Mucse
> network driver.
> 
> Fix follow error with -Werror:
>   drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c:6126:11: error: default initialization of an object of type 'const u8[6]' (aka 'const unsigned char[6]') leaves the object uninitialized and is incompatible with C++ [-Werror,-Wdefault-const-init-var-unsafe]
>    6126 |         const u8 target_addr[ETH_ALEN];
>         |                  ^
>   1 error generated.

For the record, we do not care if warnings trigger in out of tree code,
that is not justification enough to disable the warning. If this warning
is coming from rnpgbe_set_mac() like I have seen in some downstream
trees, I don't even understand why this is marked const when there is

  memcpy((void *)target_addr, addr->sa_data, netdev->addr_len);

right after it :/

> Link: https://lore.kernel.org/all/20250501-default-const-init-clang-v1-0-3d2c6c185dbb@kernel.org/
> Signed-off-by: WangYuli <wangyuli@uniontech.com>
> ---
>  scripts/Makefile.extrawarn | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index a7b680df5b24..14e22310fbbf 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -44,6 +44,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
>  # the field is within a union with other non-const members, or the containing
>  # object is not const so the field can be modified via memcpy() / memset().
>  KBUILD_CFLAGS += $(call cc-disable-warning, default-const-init-field-unsafe)
> +KBUILD_CFLAGS += $(call cc-disable-warning, default-const-init-var-unsafe)
>  else
>  
>  # gcc inanely warns about local variables called 'main'
> -- 
> 2.49.0
> 

      reply	other threads:[~2025-05-07 19:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07  9:13 [PATCH] kbuild: Disable -Wdefault-const-init-var-unsafe WangYuli
2025-05-07 19:56 ` Nathan Chancellor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250507195646.GA3495761@ax162 \
    --to=nathan@kernel.org \
    --cc=guanwentao@uniontech.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.seyfarth@gmail.com \
    --cc=masahiroy@kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=niecheng1@uniontech.com \
    --cc=wangyuli@uniontech.com \
    --cc=zhanjun@uniontech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox