Skip to contentSkip to conversation

PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable

PATCH In review Matthias Kaehlcke 3 participants 5 messages Apr 10, 2017 – Apr 11, 2017 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable

This fixes a clang warning about "implicit conversion from 'unsigned long' to 'u32'"

---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +1 -1
index dfc9a2794141..148e80d5caf1 100644
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
 
 	/* No printks while decoding is disabled! */
 	if (!dev->mmio_always_on) {
Signature · 1 line
2.12.2.715.g7642488e1d-goog
#1 lore raw
Quoted 13 lines · Matthias Kaehlcke

This fixes a clang warning about "implicit conversion from 'unsigned long' to 'u32'"

---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +0 -0
index dfc9a2794141..148e80d5caf1 100644

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, · line 183

Quoted 5 lines
drivers/pci/probe.c +1 -1
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;

Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to repeat it in all the uses?

Quoted 5 lines
drivers/pci/probe.c +0 -0
 	/* No printks while decoding is disabled! */
 	if (!dev->mmio_always_on) {
Signature · 1 line
2.12.2.715.g7642488e1d-goog
#2 lore raw
Quoted 18 lines · Bjorn Helgaas
Quoted 16 lines · Matthias Kaehlcke

This fixes a clang warning about "implicit conversion from 'unsigned long' to 'u32'"

---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +0 -0
index dfc9a2794141..148e80d5caf1 100644
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
Quoted 5 lines

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, · line 183

Quoted 2 lines
drivers/pci/probe.c +1 -1
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;

Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to repeat it in all the uses?

Fixing these "implicit conversion" warnings, especially for unsigned types, is a slippery slope. (The behavior of the conversion is well-defined.)

How about changing the type of PCI_ROM_ADDRESS_MASK instead? It's defined as ~0x7ffUL but it's only used in the context of u32.

So make it an unsigned int:
#define PCI_ROM_ADDRESS_MASK (~0x7ffU)

AFAIU, unsigned int is 32 bits on all platforms supported by Linux.

Regards.

#3 lore raw

El Tue, Apr 11, 2017 at 12:08:38PM +0200 Mason ha dit:

Quoted 34 lines · Bjorn Helgaas
Quoted 19 lines · Matthias Kaehlcke
Quoted 17 lines

This fixes a clang warning about "implicit conversion from 'unsigned long' to 'u32'"

---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +0 -0
index dfc9a2794141..148e80d5caf1 100644
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
Quoted 5 lines

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, · line 183

Quoted 2 lines
drivers/pci/probe.c +1 -1
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;

Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to repeat it in all the uses?

Fixing these "implicit conversion" warnings, especially for unsigned types, is a slippery slope. (The behavior of the conversion is well-defined.)

How about changing the type of PCI_ROM_ADDRESS_MASK instead? It's defined as ~0x7ffUL but it's only used in the context of u32.

Quoted 5 lines

So make it an unsigned int:
#define PCI_ROM_ADDRESS_MASK (~0x7ffU)

AFAIU, unsigned int is 32 bits on all platforms supported by Linux.

I considered this initially, but wasn't sure if the unsigned long mask might be needed in some cases. From the comments I interpret that there should be no problems with using a 32 bit mask everywhere.

I'll send out an updated patch shortly.

Thanks

Matthias

#4 lore raw
Quoted 39 lines · Matthias Kaehlcke

El Tue, Apr 11, 2017 at 12:08:38PM +0200 Mason ha dit:

Quoted 37 lines · Bjorn Helgaas
Quoted 19 lines · Matthias Kaehlcke
Quoted 17 lines

This fixes a clang warning about "implicit conversion from 'unsigned long' to 'u32'"

---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/probe.c +0 -0
index dfc9a2794141..148e80d5caf1 100644
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
Quoted 5 lines

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, · line 183

Quoted 2 lines
drivers/pci/probe.c +1 -1
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;

Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to repeat it in all the uses?

Fixing these "implicit conversion" warnings, especially for unsigned types, is a slippery slope. (The behavior of the conversion is well-defined.)

How about changing the type of PCI_ROM_ADDRESS_MASK instead? It's defined as ~0x7ffUL but it's only used in the context of u32.

So make it an unsigned int:
#define PCI_ROM_ADDRESS_MASK (~0x7ffU)

Quoted 8 lines
Quoted 2 lines

AFAIU, unsigned int is 32 bits on all platforms supported by Linux.

I considered this initially, but wasn't sure if the unsigned long mask might be needed in some cases. From the comments I interpret that there should be no problems with using a 32 bit mask everywhere.

I'll send out an updated patch shortly.

Full disclaimer: I'm just a grunt with no knowledge of the PCI framework. Bjorn is the authority here ;-)

Regards.