netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'liweihang' <liweihang@huawei.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"hkallweit1@gmail.com" <hkallweit1@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Linuxarm <linuxarm@huawei.com>,
	liangwenpeng <liangwenpeng@huawei.com>,
	"quentin.schulz@bootlin.com" <quentin.schulz@bootlin.com>,
	"antoine.tenart@bootlin.com" <antoine.tenart@bootlin.com>
Subject: RE: [PATCH net-next 8/8] net: phy: use '__packed' instead of '__attribute__((__packed__))'
Date: Wed, 16 Jun 2021 08:47:59 +0000	[thread overview]
Message-ID: <30f32e888f9e40a5b78549609df936d0@AcuMS.aculab.com> (raw)
In-Reply-To: <fae9811cf0404034b0da9d14fb088df1@huawei.com>

From: liweihang
> Sent: 16 June 2021 07:17
> 
> On 2021/6/14 22:28, David Laight wrote:
> > From: Weihang Li
> >> Sent: 11 June 2021 07:37
> >>
> >> Prefer __packed over __attribute__((__packed__)).
> >>
> >> Signed-off-by: Wenpeng Liang <liangwenpeng@huawei.com>
> >> Signed-off-by: Weihang Li <liweihang@huawei.com>
> >> ---
> >>  drivers/net/phy/mscc/mscc_ptp.h | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/phy/mscc/mscc_ptp.h b/drivers/net/phy/mscc/mscc_ptp.h
> >> index da34653..01f78b4 100644
> > ...
> >>  /* Represents an entry in the timestamping FIFO */
> >>  struct vsc85xx_ts_fifo {
> >>  	u32 ns;
> >>  	u64 secs:48;
> >>  	u8 sig[16];
> >> -} __attribute__((__packed__));
> >> +} __packed;
> >
> > Hmmmm I'd take some convincing that 'u64 secs:48' is anything
> > other than 'implementation defined'.
> > So using it to map a hardware structure seems wrong.
> >
> > If this does map a hardware structure it ought to have
> > 'endianness' annotations.
> > If it doesn't then why the bitfield and why packed?
> >
> > 	David
> 
> Hi David,
> 
> Thank you for your attention. You are right, I found the contents of structure
> vsc85xx_ts_fifo is got from hardware. But I'm not sure if any issues or warnings
> will be introduced into this driver after just changing 'u64 secs:48' to '__be64
> secs:48'.

I've just checked what this structure looks like - see https://godbolt.org/z/h4EqbMoso

Without any 'packed' annotations  'u64 secs:48' is aligned to an 8 byte
boundary, but is only 6 bytes wide (I don't use bitfields)
so the offset of 'sig' is 6 more than 'secs'.

But the size of the whole structure looks wrong.
I'd expect a hardware fifo so be a power of 2 big.
This one is 26 bytes (as above) or 28 bytes if the 'packed'
is only applied to 'secs' (which removed the 4 byte pad before
it while still allowing aligned 4-byte accesses to the structure.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


      reply	other threads:[~2021-06-16  8:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  6:36 [PATCH net-next 0/8] net: phy: fix some coding-style issues Weihang Li
2021-06-11  6:36 ` [PATCH net-next 1/8] net: phy: add a blank line after declarations Weihang Li
2021-06-11 14:31   ` Andrew Lunn
2021-06-15  6:12     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 2/8] net: phy: correct format of block comments Weihang Li
2021-06-11 14:36   ` Andrew Lunn
2021-06-15  6:18     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 3/8] net: phy: delete repeated word " Weihang Li
2021-06-11 14:39   ` Andrew Lunn
2021-06-15  6:21     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 4/8] net: phy: fixed formatting issues with braces Weihang Li
2021-06-11 14:41   ` Andrew Lunn
2021-06-16  6:39     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 5/8] net: phy: fixed space alignment issues Weihang Li
2021-06-11 15:30   ` Andrew Lunn
2021-06-15  6:24     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 6/8] net: phy: print the function name by __func__ instead of an fixed string Weihang Li
2021-06-11 16:05   ` Andrew Lunn
2021-06-15  6:26     ` liweihang
2021-06-16  8:14     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 7/8] net: phy: remove unnecessary line continuation Weihang Li
2021-06-11 16:06   ` Andrew Lunn
2021-06-15  6:26     ` liweihang
2021-06-11  6:36 ` [PATCH net-next 8/8] net: phy: use '__packed' instead of '__attribute__((__packed__))' Weihang Li
2021-06-11 16:07   ` Andrew Lunn
2021-06-14 14:28   ` David Laight
2021-06-16  6:17     ` liweihang
2021-06-16  8:47       ` David Laight [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=30f32e888f9e40a5b78549609df936d0@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=andrew@lunn.ch \
    --cc=antoine.tenart@bootlin.com \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=liangwenpeng@huawei.com \
    --cc=linuxarm@huawei.com \
    --cc=liweihang@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=quentin.schulz@bootlin.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;
as well as URLs for NNTP newsgroup(s).