Skip to contentSkip to conversation

PCI: tegra: Fix shiftTooManyBitsSigned warning for Tegra194

PATCH Applied Jon Hunter 3 participants 8 messages Jun 18, 2021 – Jun 25, 2021

Subsystems (3)
lore
Share & tools
lore

Jon Hunter

author maintainer
#0 lore raw

PATCH 1/1 PCI: tegra: Fix shiftTooManyBitsSigned warning for Tegra194

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
author maintainer
#1 lore raw
Quoted 11 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

Quoted 7 lines
  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194

Looks like I messed up the format of the Fixes: tag and it should be ...

Fixes c57247f940e8 ("PCI: tegra: Add support for PCIe endpoint mode in Tegra194")
Quoted 19 lines
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
nvpublic
#2 lore raw
In reply to Jon Hunter
Quoted 11 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

Quoted 5 lines
  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

The subject and commit log should describe the problem we're fixing. The *warning* is not the problem; the problem is the undefined behavior.

I'll fix this up, no need to repost for this.

Quoted 22 lines
Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#3 lore raw
Quoted 18 lines · Bjorn Helgaas
Quoted 11 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

Quoted 5 lines
  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

Quoted 5 lines

The subject and commit log should describe the problem we're fixing. The *warning* is not the problem; the problem is the undefined behavior.

I'll fix this up, no need to repost for this.

Hi Bjorn,

I can fix it up myself, just wanted to ask if you merged it already, it does not look like but I thought I'd check.

Thanks,
Lorenzo

Quoted 22 lines
Quoted 22 lines
Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#4 lore raw
Quoted 23 lines · Lorenzo Pieralisi
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

Quoted 5 lines
  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

The subject and commit log should describe the problem we're fixing. The *warning* is not the problem; the problem is the undefined behavior.

Quoted 6 lines
Quoted 1 line

I'll fix this up, no need to repost for this.

Hi Bjorn,

I can fix it up myself, just wanted to ask if you merged it already, it does not look like but I thought I'd check.

Oops, sorry, I guess I dropped the ball on this one and didn't get it merged. When you do, can you update the subject as well, e.g.,

s/PCI: tegra/PCI: tegra194/

to differentiate from the other "tegra" driver?

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#5 lore raw
In reply to Bjorn Helgaas
Quoted 18 lines · Bjorn Helgaas
Quoted 11 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

Quoted 5 lines
  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

Quoted 5 lines

The subject and commit log should describe the problem we're fixing. The *warning* is not the problem; the problem is the undefined behavior.

I'll fix this up, no need to repost for this.

I merged this from Lorenzo's branch, but I updated the commit log like this because the undefined behavior is the real problem:

PCI: tegra194: Fix tegra_pcie_ep_raise_msi_irq() ill-defined shift

tegra_pcie_ep_raise_msi_irq() shifted a signed 32-bit value left by 31 bits. The behavior of this is implementation-defined.

Replace the shift by BIT(), which is well-defined.

Found by cppcheck:

$ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability: Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
^

[bhelgaas: commit log]
Fixes c57247f940e8 ("PCI: tegra: Add support for PCIe endpoint mode in Tegra194")
Quoted 22 lines
Quoted 22 lines
Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#6 lore raw
Quoted 19 lines · Bjorn Helgaas
Quoted 18 lines · Bjorn Helgaas
Quoted 16 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

  appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
                      ^

The above warning occurs because the '1' is treated as a signed type and so fix this by using the 'BIT' macro to ensure that this is defined as a unsigned type.

Quoted 3 lines
Quoted 3 lines

The subject and commit log should describe the problem we're fixing. The *warning* is not the problem; the problem is the undefined behavior.

I updated the commit log accordingly but I did not change the subject :-/

Quoted 6 lines
Quoted 1 line

I'll fix this up, no need to repost for this.

I merged this from Lorenzo's branch, but I updated the commit log like this because the undefined behavior is the real problem:

PCI: tegra194: Fix tegra_pcie_ep_raise_msi_irq() ill-defined shift

Yep, I forgot to update the subject, thanks for doing that.

Lorenzo

Quoted 45 lines

tegra_pcie_ep_raise_msi_irq() shifted a signed 32-bit value left by 31 bits. The behavior of this is implementation-defined.

Replace the shift by BIT(), which is well-defined.

Found by cppcheck:

$ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c Checking drivers/pci/controller/dwc/pcie-tegra194.c ...

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability: Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
^

[bhelgaas: commit log]
Fixes c57247f940e8 ("PCI: tegra: Add support for PCIe endpoint mode in Tegra194")
Quoted 22 lines
Quoted 22 lines
Fixes c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 8fc08336f76e..3c1feeab104f 100644
@@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
 	if (unlikely(irq > 31))
 		return -EINVAL;
 
-	appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
+	appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#7 lore raw
In reply to Jon Hunter
Quoted 6 lines · Jon Hunter

The cppcheck tool issues the following warning for the Tegra194 PCIe driver ...

 $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
 Checking drivers/pci/controller/dwc/pcie-tegra194.c ...
Quoted 6 lines

drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]

[...]

Applied to pci/tegra, thanks!

[1/1] PCI: tegra194: Fix shiftTooManyBitsSigned warning for Tegra194

      https://git.kernel.org/lpieralisi/pci/c/b1eca3a544

Thanks,
Lorenzo