Message ID | 20190323015359.7231-4-marek.vasut@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | [V3,1/6] PCI: rcar: Clean up remaining macros defining bits | expand |
Hi Marek, On Sat, Mar 23, 2019 at 2:54 AM <marek.vasut@gmail.com> wrote: > From: Marek Vasut <marek.vasut+renesas@gmail.com> > > Replace (8 * n) with (n << 3) to make bit shift operations consistent. > No functional change. > > Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> Thanks for your patch! Where is the inconsistency? The driver consistently uses 1. multiplications for bit offset calculations, 2. shifts for bit field extraction or insertion. While technically equivalent, I think your change makes the code harder to read: the values are multiplied by eight to convert from number of bytes to number of bits, so IMHO "BITS_PER_BYTE * n" would be more readable. Gr{oetje,eeting}s, Geert
On 3/25/19 9:26 AM, Geert Uytterhoeven wrote: > Hi Marek, > > On Sat, Mar 23, 2019 at 2:54 AM <marek.vasut@gmail.com> wrote: >> From: Marek Vasut <marek.vasut+renesas@gmail.com> >> >> Replace (8 * n) with (n << 3) to make bit shift operations consistent. >> No functional change. >> >> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> > > Thanks for your patch! > > Where is the inconsistency? The driver consistently uses > 1. multiplications for bit offset calculations, > 2. shifts for bit field extraction or insertion. > > While technically equivalent, I think your change makes the code harder > to read: the values are multiplied by eight to convert from number of > bytes to number of bits, so IMHO "BITS_PER_BYTE * n" would be more > readable. Sure
diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c index a2d3855b15ea..f835e4341590 100644 --- a/drivers/pci/controller/pcie-rcar.c +++ b/drivers/pci/controller/pcie-rcar.c @@ -169,7 +169,7 @@ enum { static void rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data) { - unsigned int shift = 8 * (where & 3); + unsigned int shift = (where & 3) << 3; u32 val = rcar_pci_read_reg(pcie, where & ~3); val &= ~(mask << shift); @@ -179,7 +179,7 @@ static void rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data) static u32 rcar_read_conf(struct rcar_pcie *pcie, int where) { - unsigned int shift = 8 * (where & 3); + unsigned int shift = (where & 3) << 3; u32 val = rcar_pci_read_reg(pcie, where & ~3); return val >> shift; @@ -280,9 +280,9 @@ static int rcar_pcie_read_conf(struct pci_bus *bus, unsigned int devfn, } if (size == 1) - *val = (*val >> (8 * (where & 3))) & 0xff; + *val = (*val >> ((where & 3) << 3)) & 0xff; else if (size == 2) - *val = (*val >> (8 * (where & 2))) & 0xffff; + *val = (*val >> ((where & 2) << 3)) & 0xffff; dev_dbg(&bus->dev, "pcie-config-read: bus=%3d devfn=0x%04x where=0x%04x size=%d val=0x%08lx\n", bus->number, devfn, where, size, (unsigned long)*val); @@ -308,11 +308,11 @@ static int rcar_pcie_write_conf(struct pci_bus *bus, unsigned int devfn, bus->number, devfn, where, size, (unsigned long)val); if (size == 1) { - shift = 8 * (where & 3); + shift = (where & 3) << 3; data &= ~(0xff << shift); data |= ((val & 0xff) << shift); } else if (size == 2) { - shift = 8 * (where & 2); + shift = (where & 2) << 3; data &= ~(0xffff << shift); data |= ((val & 0xffff) << shift); } else