mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Andrew Lunn <andrew@lunn.ch>,
	"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>,
	Jakub Kicinski <kuba@kernel.org>, 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 1/2][next] UAPI: ethtool: Use __struct_group() in struct ethtool_link_settings
Date: Wed, 23 Oct 2024 15:30:25 -0600	[thread overview]
Message-ID: <2b7e1535-2d7a-4c7c-9687-9ddd42392802@embeddedor.com> (raw)
In-Reply-To: <53721db6-f4b1-4394-ab2a-045f214bd2fa@lunn.ch>



On 21/10/24 14:11, Andrew Lunn wrote:
>>   struct ethtool_link_settings {
>> -	__u32	cmd;
>> -	__u32	speed;
>> -	__u8	duplex;
>> -	__u8	port;
>> -	__u8	phy_address;
>> -	__u8	autoneg;
>> -	__u8	mdio_support;
>> -	__u8	eth_tp_mdix;
>> -	__u8	eth_tp_mdix_ctrl;
>> -	__s8	link_mode_masks_nwords;
>> -	__u8	transceiver;
>> -	__u8	master_slave_cfg;
>> -	__u8	master_slave_state;
>> -	__u8	rate_matching;
>> -	__u32	reserved[7];
>> +	/* New members MUST be added within the __struct_group() macro below. */
>> +	__struct_group(ethtool_link_settings_hdr, hdr, /* no attrs */,
>> +		__u32	cmd;
>> +		__u32	speed;
>> +		__u8	duplex;
>> +		__u8	port;
>> +		__u8	phy_address;
>> +		__u8	autoneg;
>> +		__u8	mdio_support;
>> +		__u8	eth_tp_mdix;
>> +		__u8	eth_tp_mdix_ctrl;
>> +		__s8	link_mode_masks_nwords;
>> +		__u8	transceiver;
>> +		__u8	master_slave_cfg;
>> +		__u8	master_slave_state;
>> +		__u8	rate_matching;
>> +		__u32	reserved[7];
>> +	);
>>   	__u32	link_mode_masks[];
> 
> Dumb C question. What are the padding rules for a union, compared to
> base types? Do we know for sure the compiler is not going pad this
> structure differently because of the union?

We've been using the struct_group() family of helpers in Linux for years,
and we haven't seen any issues with padding an alignment. So, it seems
to do its job just fine. :)

Thanks
--
Gustavo

> 
> It is however nicely constructed. The 12 __u8 making 3 32bit words, so
> we have a total of 12 32bit words, or 6 64bit words, before the
> link_mode_masks[], so i don't think padding is technically an issue,
> but it would be nice to know the C standard guarantees this.
> 
> 	Andrew

  reply	other threads:[~2024-10-23 21:30 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: Avoid thousands of -Wflex-array-member-not-at-end warnings 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 [this message]
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
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=2b7e1535-2d7a-4c7c-9687-9ddd42392802@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@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

Powered by JetHome