Re: [PATCH 07/21] PCI: designware: Make use of IS_ALIGNED()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 4, 2019 at 10:38 AM Joe Perches <joe@xxxxxxxxxxx> 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



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux