Skip to contentSkip to conversation

PCI: iproc: fix 32-bit build

PATCH In review Arnd Bergmann 3 participants 9 messages Nov 22, 2016 – Nov 23, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 PCI: iproc: fix 32-bit build

The newly added code to setup the inbound ranges causes a link error on 32-bit machines from a 32-bit division:

drivers/pci/host/pcie-iproc.o: In function `iproc_pcie_setup_ib':
pcie-iproc.c:(.text.iproc_pcie_setup_ib+0x14c): undefined reference to `__aeabi_uldivmod'

As both sides of the division are always power-of-two numbers and we already rely on that, we can use a shift instead.

Fixes 87c240b19bba ("PCI: iproc: Add inbound DMA mapping support")
---
 drivers/pci/host/pcie-iproc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pcie-iproc.c +1 -1
index d10e6aa32e0d..857ff5198317 100644
@@ -865,7 +865,7 @@ static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
 	 * Now program the IMAP registers.  Each IARR region may have one or
 	 * more IMAP windows.
 	 */
-	size /= nr_windows;
+	size >>= ilog2(nr_windows);
 	for (window_idx = 0; window_idx < nr_windows; window_idx++) {
 		val = readl(pcie->base + imap_offset);
 		val |= lower_32_bits(axi_addr) | IMAP_VALID;
Signature · 1 line
2.9.0
#1 lore raw

PATCH 2/2 PCI: iproc: avoid maybe-uninitialized warning

gcc notices that calling iproc_pcie_setup_ib with ib->nr_regions==0 would result in an uninitialized return value:

drivers/pci/host/pcie-iproc.c: In function 'iproc_pcie_setup_ib':
drivers/pci/host/pcie-iproc.c:894:6: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This can't really happen, but the correct behavior of the function is probably to return -EINVAL if it ever did.

Fixes 4213e15c364e ("PCI: iproc: Make outbound mapping code more generic")
---
 drivers/pci/host/pcie-iproc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/host/pcie-iproc.c +1 -0
index 857ff5198317..0359569c8d78 100644
@@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 
 		}
 	}
+	ret = -EINVAL;
 err_ib:
 	dev_err(dev, "unable to configure inbound mapping\n");
 	dev_err(dev, "axi %pap, pci %pap, res size %pap\n",
Signature · 1 line
2.9.0
#2 lore raw

Re: [PATCH 2/2] PCI: iproc: avoid maybe-uninitialized warning

Hi Arnd,

Quoted 21 lines · Arnd Bergmann

gcc notices that calling iproc_pcie_setup_ib with ib->nr_regions==0 would result in an uninitialized return value:

drivers/pci/host/pcie-iproc.c: In function 'iproc_pcie_setup_ib':
drivers/pci/host/pcie-iproc.c:894:6: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This can't really happen, but the correct behavior of the function is probably to return -EINVAL if it ever did.

Fixes 4213e15c364e ("PCI: iproc: Make outbound mapping code more generic")
---
 drivers/pci/host/pcie-iproc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/host/pcie-iproc.c +0 -0
index 857ff5198317..0359569c8d78 100644

drivers/pci/host/pcie-iproc.c static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, · line 942

Quoted 7 lines
drivers/pci/host/pcie-iproc.c +1 -0
@@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 
 		}
 	}
+	ret = -EINVAL;
 err_ib:
 	dev_err(dev, "unable to configure inbound mapping\n");
 	dev_err(dev, "axi %pap, pci %pap, res size %pap\n",

This change is good, but in my opinion, a further improvement for clarity would be to initialize 'ret' to -EINVAL in the beginning of this function when 'ret' is declared. What do you think?

Thanks,

Ray

#3 lore raw

Re: [PATCH 2/2] PCI: iproc: avoid maybe-uninitialized warning

Quoted 6 lines · CET Ray Jui
Quoted 6 lines
drivers/pci/host/pcie-iproc.c +0 -0
index 857ff5198317..0359569c8d78 100644
@@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 
Quoted 12 lines

drivers/pci/host/pcie-iproc.c static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, · line 942

Quoted 7 lines
drivers/pci/host/pcie-iproc.c +1 -0
              }
      }
+     ret = -EINVAL;
 err_ib:
      dev_err(dev, "unable to configure inbound mapping\n");
      dev_err(dev, "axi %pap, pci %pap, res size %pap\n",

This change is good, but in my opinion, a further improvement for clarity would be to initialize 'ret' to -EINVAL in the beginning of this function when 'ret' is declared. What do you think?

I never do that, see https://rusty.ozlabs.org/?p=232 for a great explanation about why.

Arnd

#4 lore raw

Re: [PATCH 2/2] PCI: iproc: avoid maybe-uninitialized warning

Quoted 20 lines · Arnd Bergmann
Quoted 6 lines · CET Ray Jui
Quoted 6 lines
drivers/pci/host/pcie-iproc.c +0 -0
index 857ff5198317..0359569c8d78 100644
@@ -936,6 +936,7 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 
Quoted 12 lines

drivers/pci/host/pcie-iproc.c static int iproc_pcie_setup_ib(struct iproc_pcie *pcie, · line 942

Quoted 7 lines
drivers/pci/host/pcie-iproc.c +1 -0
              }
      }
+     ret = -EINVAL;
 err_ib:
      dev_err(dev, "unable to configure inbound mapping\n");
      dev_err(dev, "axi %pap, pci %pap, res size %pap\n",

This change is good, but in my opinion, a further improvement for clarity would be to initialize 'ret' to -EINVAL in the beginning of this function when 'ret' is declared. What do you think?

Quoted 5 lines

I never do that, see https://rusty.ozlabs.org/?p=232 for a great explanation about why.

Arnd

Okay got it. Thanks!

Ray

Acked-by on v1 1/2
#5 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann

The newly added code to setup the inbound ranges causes a link error on 32-bit machines from a 32-bit division:

drivers/pci/host/pcie-iproc.o: In function `iproc_pcie_setup_ib':
pcie-iproc.c:(.text.iproc_pcie_setup_ib+0x14c): undefined reference to `__aeabi_uldivmod'

As both sides of the division are always power-of-two numbers and we already rely on that, we can use a shift instead.

Fixes 87c240b19bba ("PCI: iproc: Add inbound DMA mapping support")
---
 drivers/pci/host/pcie-iproc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pcie-iproc.c +0 -0
index d10e6aa32e0d..857ff5198317 100644

drivers/pci/host/pcie-iproc.c static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx, · line 871

Quoted 8 lines
drivers/pci/host/pcie-iproc.c +1 -1
@@ -865,7 +865,7 @@ static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
 	 * Now program the IMAP registers.  Each IARR region may have one or
 	 * more IMAP windows.
 	 */
-	size /= nr_windows;
+	size >>= ilog2(nr_windows);
 	for (window_idx = 0; window_idx < nr_windows; window_idx++) {
 		val = readl(pcie->base + imap_offset);
 		val |= lower_32_bits(axi_addr) | IMAP_VALID;

Hmmm, somehow we've never seen this link error for the ARM32 based platforms that we build for. Does it behave differently between different versions of compilers?

Nevertheless, this is a good change to take, thanks!

#6 lore raw
Quoted 6 lines · CET Ray Jui

Hmmm, somehow we've never seen this link error for the ARM32 based platforms that we build for. Does it behave differently between different versions of compilers?

Nevertheless, this is a good change to take, thanks!

I looked at it again, and see now that it only happens with a 64-bit RESOURCE_SIZE_T, which is only used on 32-bit platforms with more than 4GB of memory addresses. It would however show up in a multiplatform distro build for ARMv7VE, so the fix is still clearly needed.

Arnd

#7 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines · CET Ray Jui

Hmmm, somehow we've never seen this link error for the ARM32 based platforms that we build for. Does it behave differently between different versions of compilers?

Nevertheless, this is a good change to take, thanks!

Quoted 8 lines

I looked at it again, and see now that it only happens with a 64-bit RESOURCE_SIZE_T, which is only used on 32-bit platforms with more than 4GB of memory addresses. It would however show up in a multiplatform distro build for ARMv7VE, so the fix is still clearly needed.

Arnd

Yes, got it for how it showed up in your environment, :)

This change stands good as it has been.

Thanks,

Ray

#8 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

The newly added code to setup the inbound ranges causes a link error on 32-bit machines from a 32-bit division:

drivers/pci/host/pcie-iproc.o: In function `iproc_pcie_setup_ib':
pcie-iproc.c:(.text.iproc_pcie_setup_ib+0x14c): undefined reference to `__aeabi_uldivmod'

As both sides of the division are always power-of-two numbers and we already rely on that, we can use a shift instead.

Fixes 87c240b19bba ("PCI: iproc: Add inbound DMA mapping support")

I folded these fixes into the pci/host-iproc branch for v4.10, thanks!

For some reason, I don't see Ray's responses on the list. Maybe still some email problem?

Quoted 25 lines
---
 drivers/pci/host/pcie-iproc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pcie-iproc.c +1 -1
index d10e6aa32e0d..857ff5198317 100644
@@ -865,7 +865,7 @@ static int iproc_pcie_ib_write(struct iproc_pcie *pcie, int region_idx,
 	 * Now program the IMAP registers.  Each IARR region may have one or
 	 * more IMAP windows.
 	 */
-	size /= nr_windows;
+	size >>= ilog2(nr_windows);
 	for (window_idx = 0; window_idx < nr_windows; window_idx++) {
 		val = readl(pcie->base + imap_offset);
 		val |= lower_32_bits(axi_addr) | IMAP_VALID;
Signature · 7 lines
2.9.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel