[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdkr0=gdTUG9_2ACBY-WxEerzcK60WHBsmy+hz7rD-yZNA@mail.gmail.com>
Date: Tue, 17 Sep 2019 09:00:59 -0700
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: Jose Abreu <Jose.Abreu@...opsys.com>
Cc: David Laight <David.Laight@...lab.com>,
Nathan Chancellor <natechancellor@...il.com>,
Tom Lendacky <thomas.lendacky@....com>,
Giuseppe Cavallaro <peppe.cavallaro@...com>,
Alexandre Torgue <alexandre.torgue@...com>,
"David S. Miller" <davem@...emloft.net>,
Ilie Halip <ilie.halip@...il.com>,
David Bolvansky <david.bolvansky@...il.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"clang-built-linux@...glegroups.com"
<clang-built-linux@...glegroups.com>
Subject: Re: -Wsizeof-array-div warnings in ethernet drivers
On Tue, Sep 17, 2019 at 6:27 AM Jose Abreu <Jose.Abreu@...opsys.com> wrote:
>
> From: David Laight <David.Laight@...LAB.COM>
> Date: Sep/17/2019, 11:36:21 (UTC+00:00)
>
> > From: Jose Abreu
> > > Sent: 17 September 2019 08:59
> > > From: Nathan Chancellor <natechancellor@...il.com>
> > > Date: Sep/17/2019, 08:32:32 (UTC+00:00)
> > >
> > > > Hi all,
> > > >
> > > > Clang recently added a new diagnostic in r371605, -Wsizeof-array-div,
> > > > that tries to warn when sizeof(X) / sizeof(Y) does not compute the
> > > > number of elements in an array X (i.e., sizeof(Y) is wrong). See that
> > > > commit for more details:
> > ...
> > > > ../drivers/net/ethernet/amd/xgbe/xgbe-dev.c:361:49: warning: expression
> > > > does not compute the number of elements in this array; element type is
> > > > 'u8' (aka 'unsigned char'), not 'u32' (aka 'unsigned int')
> > > > [-Wsizeof-array-div]
> > > > unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
> > > > ~~~~~~~~~~~~~~ ^
> > ...
> > > > What is the reasoning behind having the key being an array of u8s but
> > > > seemlingly converting it into an array of u32s? It's not immediately
> > > > apparent from reading over the code but I am not familiar with it so I
> > > > might be making a mistake. I assume this is intentional? If so, the
> > > > warning can be silenced and we'll send patches to do so but we want to
> > > > make sure we aren't actually papering over a mistake.
> > >
> > > This is because we write 32 bits at a time to the reg but internally the
> > > driver uses 8 bits to store the array. If you look at
> > > dwxgmac2_rss_configure() you'll see that cfg->key is casted to u32 which
> > > is the value we use in HW writes. Then the for loop just does the math
> > > to check how many u32's has to write.
> >
> > That stinks of a possible misaligned data access.....
>
> It's possible to happen only if structure field is not aligned. I guess
> I can either change all to u32 or just __align the field of the struct
Would __aligning the struct still produce the warning? It's good to
know that this case is intentional, but I would like to consider other
instances of it before we seriously consider turning it off. If the
driver can be rewritten to just make use of u32, I would find that
preferrable.
--
Thanks,
~Nick Desaulniers
Powered by blists - more mailing lists