Skip to contentSkip to conversation

drivers: pci: initialise class to 0 before reading

PATCH New Hugh Cole-Baker 2 participants 4 messages Jan 1, 2020 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: pci: initialise class to 0 before reading

Otherwise, uninitialised memory from the upper 32 bits can end up in find_id.class, and this causes bugs later when looking for a driver for the class.

---
 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-uclass.c +1 -1
index fab20fc60e..c28a1cc363 100644
@@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
 	     bdf += PCI_BDF(0, 0, 1)) {
 		struct pci_child_platdata *pplat;
 		struct udevice *dev;
-		ulong class;
+		ulong class = 0;
 
 		if (!PCI_FUNC(bdf))
 			found_multi = false;
Signature · 1 line
2.17.2 (Apple Git-113)
#1 lore raw

PATCH 1/1 drivers: pci: initialise class to 0 before reading

Quoted 15 lines · Hugh Cole-Baker

Otherwise, uninitialised memory from the upper 32 bits can end up in find_id.class, and this causes bugs later when looking for a driver for the class.

---
 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-uclass.c +0 -0
index fab20fc60e..c28a1cc363 100644

drivers/pci/pci-uclass.c int pci_bind_bus_devices(struct udevice *bus)

Quoted 9 lines
drivers/pci/pci-uclass.c +1 -2
@@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
             bdf += PCI_BDF(0, 0, 1)) {
                struct pci_child_platdata *pplat;
                struct udevice *dev;
-               ulong class;
+               ulong class = 0;
 
                if (!PCI_FUNC(bdf))
                        found_multi = false;
--

I see class is initialized in the call to:

pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, &class,

    PCI_SIZE_32);

class >>= 8;

Regards,
Bin

#2 lore raw

PATCH 1/1 drivers: pci: initialise class to 0 before reading

Hi Bin,

Quoted 30 lines · Bin Meng
Quoted 15 lines · Hugh Cole-Baker

Otherwise, uninitialised memory from the upper 32 bits can end up in find_id.class, and this causes bugs later when looking for a driver for the class.

---
drivers/pci/pci-uclass.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-uclass.c +0 -0
index fab20fc60e..c28a1cc363 100644

drivers/pci/pci-uclass.c int pci_bind_bus_devices(struct udevice *bus)

Quoted 9 lines
drivers/pci/pci-uclass.c +1 -2
@@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
            bdf += PCI_BDF(0, 0, 1)) {
               struct pci_child_platdata *pplat;
               struct udevice *dev;
-               ulong class;
+               ulong class = 0;
 
               if (!PCI_FUNC(bdf))
                       found_multi = false;
--

I see class is initialized in the call to:

Quoted 4 lines

pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, &class,
PCI_SIZE_32);
class >>= 8;

Maybe the driver I'm working with is doing its read_config wrongly? I'm trying to use this Rockchip PCIe driver [1] with upstream u-boot. The driver casts &class to u32*, uses readl() and only sets the lower 32 bits. I was assuming that this was normal for a read of PCI_SIZE_32. However, looking at some of the other drivers, it seems like it should be using pci_conv_32_to_size() instead?

[1] https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L435

Thanks,
Hugh

Quoted 2 lines

Regards,
Bin

#3 lore raw

PATCH 1/1 drivers: pci: initialise class to 0 before reading

Hi Hugh,

Quoted 38 lines · Hugh Cole-Baker

Hi Bin,

Quoted 30 lines · Bin Meng
Quoted 15 lines · Hugh Cole-Baker

Otherwise, uninitialised memory from the upper 32 bits can end up in find_id.class, and this causes bugs later when looking for a driver for the class.

---
drivers/pci/pci-uclass.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-uclass.c +0 -0
index fab20fc60e..c28a1cc363 100644

drivers/pci/pci-uclass.c int pci_bind_bus_devices(struct udevice *bus)

Quoted 9 lines
drivers/pci/pci-uclass.c +1 -2
@@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
            bdf += PCI_BDF(0, 0, 1)) {
               struct pci_child_platdata *pplat;
               struct udevice *dev;
-               ulong class;
+               ulong class = 0;
 
               if (!PCI_FUNC(bdf))
                       found_multi = false;
--

I see class is initialized in the call to:

Quoted 4 lines

pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, &class,
PCI_SIZE_32);
class >>= 8;

Quoted 7 lines

Maybe the driver I'm working with is doing its read_config wrongly? I'm trying to use this Rockchip PCIe driver [1] with upstream u-boot. The driver casts &class to u32*, uses readl() and only sets the lower 32 bits. I was assuming that this was normal for a read of PCI_SIZE_32. However, looking at some of the other drivers, it seems like it should be using pci_conv_32_to_size() instead?

The bug should be that

https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L318

u32 *val should be declared as ulong *val.

Quoted 2 lines

[1] https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L435

Regards,
Bin