mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Jakub Kicinski <kuba@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Michael Chan <michael.chan@broadcom.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Potnuri Bharat Teja <bharat@chelsio.com>,
	Christian Benvenuti <benve@cisco.com>,
	Satish Kharat <satishkh@cisco.com>,
	Manish Chopra <manishc@marvell.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH 2/2][next] net: ethtool: Avoid thousands of -Wflex-array-member-not-at-end warnings
Date: Mon, 28 Oct 2024 17:32:53 -0600	[thread overview]
Message-ID: <158eb222-d875-4f96-b027-83854e5f4275@embeddedor.com> (raw)
In-Reply-To: <20241028162131.39e280bd@kernel.org>



On 28/10/24 17:21, Jakub Kicinski wrote:
> On Mon, 21 Oct 2024 13:02:27 -0600 Gustavo A. R. Silva wrote:
>> Fix 3338 of the following -Wflex-array-member-not-at-end warnings:
>>
>> include/linux/ethtool.h:214:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> I don't see any change in the number of warnings with W=1:
> gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
> Is it only enabled with W=2?

-Wfamnae is not currently part of any upstream build. We are working
to have it enabled. So, these warnings are the ones I see in my local
build with the following patch applied:

diff --git a/Makefile b/Makefile
index d4a41c44e0fc..08d18b5d01f5 100644
--- a/Makefile
+++ b/Makefile
@@ -1002,6 +1002,9 @@ NOSTDINC_FLAGS += -nostdinc
  # perform bounds checking.
  KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)

+# Avoid flexible-array members not at the end of composite structure.
+KBUILD_CFLAGS += $(call cc-option, -Wflex-array-member-not-at-end)
+
  #Currently, disable -Wstringop-overflow for GCC 11, globally.
  KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
  KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)


> 
>> Additionally, update the type of some variables in various functions
>> that don't access the flexible-array member, changing them to the
>> newly created `struct ethtool_link_settings_hdr`.
> 
> Why? Please avoid unnecessary code changes.

This is actually necessary. As the type of the conflicting middle members
changed, those instances that expect the type to be `struct ethtool_link_settings`
should be adjusted to the new type. Another option is to leave the type
unchanged and instead use container_of. See below.

So, instead of this:

-	struct ethtool_link_settings *base = &link_ksettings->base;
+	struct ethtool_link_settings_hdr *base = &link_ksettings->base;

we would do something like this:

-	struct ethtool_link_settings *base = &link_ksettings->base;
+	struct ethtool_link_settings *base = container_of(&link_ksettings->base,
+							  struct struct ethtool_link_settings, hdr);

I think that in this case, we could avoid using `container_of()`, but
if you prefer that, I can update the patch.


> 
>>   include/linux/ethtool.h                            |  2 +-
> 
> This is probably where most of the warnings come from.
> Please split the changes to this header file as a separate patch
> for ease of review / validation.
> 

Sure thing!

Thanks
--
Gustavo


  reply	other threads:[~2024-10-28 23:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 19:01 [PATCH 0/2][next] UAPI: net/ethtool: " Gustavo A. R. Silva
2024-10-21 19:01 ` [PATCH 1/2][next] UAPI: ethtool: Use __struct_group() in struct ethtool_link_settings Gustavo A. R. Silva
2024-10-21 20:11   ` Andrew Lunn
2024-10-23 21:30     ` Gustavo A. R. Silva
2024-10-21 19:02 ` [PATCH 2/2][next] net: ethtool: Avoid thousands of -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-10-28 23:21   ` Jakub Kicinski
2024-10-28 23:32     ` Gustavo A. R. Silva [this message]
2024-10-29  0:32       ` Jakub Kicinski
2024-10-29  2:37         ` Gustavo A. R. Silva
2024-10-29 13:56           ` Jakub Kicinski
2024-10-29 13:58   ` Jakub Kicinski
2024-10-29 16:55     ` Gustavo A. R. Silva
2024-10-29 18:08       ` Jakub Kicinski
2024-10-29 18:18         ` Gustavo A. R. Silva
2024-10-29 18:39           ` Jakub Kicinski
2024-10-29 18:48             ` Gustavo A. R. Silva
2024-10-29 18:54               ` Jakub Kicinski
2024-10-29 19:18                 ` Gustavo A. R. Silva
2024-10-29 20:00                   ` Jakub Kicinski
2024-10-29 22:06                     ` Gustavo A. R. Silva

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=158eb222-d875-4f96-b027-83854e5f4275@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=benve@cisco.com \
    --cc=bharat@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manishc@marvell.com \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=satishkh@cisco.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

all inboxes | Powered by JetHome®