lkml.org 
[lkml]   [2019]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 07/21] PCI: designware: Make use of IS_ALIGNED()
On Fri, Jan 4, 2019 at 10:38 AM Joe Perches <joe@perches.com> wrote:
>
> On Wed, 2019-01-02 at 09:33 +0000, Gustavo Pimentel wrote:
> > On 21/12/2018 07:27, Andrey Smirnov wrote:
> > > Make the intent a bit more clear as well as get rid of explicit
> > > arithmetic by using IS_ALIGNED() to determine if "addr" is aligned to
> > > "size". No functional change intended.
> []
> > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
> []
> > > @@ -22,7 +22,7 @@
> > >
> > > int dw_pcie_read(void __iomem *addr, int size, u32 *val)
> > > {
> > > - if ((uintptr_t)addr & (size - 1)) {
> > > + if (!IS_ALIGNED((uintptr_t)addr, size)) {
>
> The (uintptr_t) cast could probably be removed as well.
>

Unfortunately no. IS_ALIGNED(x, a) is going to expand (((x) &
((typeof(x))(a) - 1)) == 0), so we'll end up with (((addr) & ((void
*)(size) - 1)) which has two problems:

1. It tries to use & operator on two void * pointers
2. On 64-bit platforms (e.g. AArch64) it will try to cast an "int" to
a pointer, resulting in "warning: cast to pointer from integer of
different size"

When working on it, I initially wrote the code without the cast, but
was quickly reprimanded by GCC and had to add it back in.

Thanks,
Andrey Smirnov

\
 
 \ /
  Last update: 2019-01-04 19:53    [W:0.068 / U:4.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site