lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7bab865c-b5f6-4319-ba0f-1d0ddc09f9cd@lunn.ch>
Date: Fri, 16 Aug 2024 23:04:41 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Jijie Shao <shaojijie@...wei.com>
Cc: yisen.zhuang@...wei.com, salil.mehta@...wei.com, davem@...emloft.net,
	edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
	horms@...nel.org, shenjian15@...wei.com, wangpeiyang1@...wei.com,
	liuyonglong@...wei.com, sudongming1@...wei.com,
	xujunsheng@...wei.com, shiyongbang@...wei.com, jdamato@...tly.com,
	jonathan.cameron@...wei.com, shameerali.kolothum.thodi@...wei.com,
	netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH V2 net-next 03/11] net: hibmcge: Add mdio and
 hardware configuration supported in this module

On Fri, Aug 16, 2024 at 02:10:36PM +0800, Jijie Shao wrote:
> 
> on 2024/8/16 10:25, Andrew Lunn wrote:
> > > +struct hbg_mdio_command {
> > > +	union {
> > > +		struct {
> > > +			u32 mdio_devad : 5;
> > > +			u32 mdio_prtad :5;
> > > +			u32 mdio_op : 2;
> > > +			u32 mdio_st : 2;
> > > +			u32 mdio_start : 1;
> > > +			u32 mdio_clk_sel : 1;
> > > +			u32 mdio_auto_scan : 1;
> > > +			u32 mdio_clk_sel_exp : 1;
> > > +			u32 rev : 14;
> > > +		};
> > > +		u32 bits;
> > > +	};
> > > +};
> > This is generally not the way to do this. Please look at the macros in
> > include/linux/bitfield.h. FIELD_PREP, GENMASK, BIT, FIELD_GET
> > etc. These are guaranteed to work for both big and little endian, and
> > you avoid issues where the compiler decides to add padding in your
> > bitfields.
> > 
> > 	Andrew
> 
> Thanks, I already know about macros like FIELD_PREP or FIELD_GET.
> and these macros are already used in parts of this patch set.
> 
> But I think this writing style in here very convenient.
> Although padding needs to be added during definition,
> but you can use command.mdio_start or command->mdio_start
> to access specific bitfields.
> 
> Although FIELD_PREP/FIELD_GET is convenient,
> But it also needs to define the mask using BIT or GENMASK,
> and the mask can only be a static constant,
> which makes it difficult to use sometimes.

Have a look around. How many drivers use this sort of union? How many
use bitfield.h. There is a reason the union is not used. I suspect
there is nothing in the C standard which guarantees it works.

      Andrew

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ