Skip to contentSkip to conversation

PCI: Fix lock symmetry in pci_slot_unlock()

PATCH Applied Ilpo Järvinen 4 participants 4 messages May 5, 2025

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

PATCH v2 1/1 PCI: Fix lock symmetry in pci_slot_unlock()

The commit a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") made the lock function to call depend on dev->subordinate but left pci_slot_unlock() unmodified creating locking asymmetry compared with pci_slot_lock().

Because of the asymmetric lock handling, the same bridge device is unlocked twice. First pci_bus_unlock() unlocks bus->self and then pci_slot_unlock() will unconditionally unlock the same bridge device.

Move pci_dev_unlock() inside an else branch to match the logic in pci_slot_lock().

Fixes a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")

---

v2:
- Improve changelog (Lukas)
- Added Cc stable

 drivers/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/pci.c +2 -1
index 4d7c9f64ea24..26507aa906d7 100644
@@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
 			continue;
 		if (dev->subordinate)
 			pci_bus_unlock(dev->subordinate);
-		pci_dev_unlock(dev);
+		else
+			pci_dev_unlock(dev);
 	}
 }
 

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8

Signature · 1 line
2.39.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Ilpo Järvinen

The commit a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") made the lock function to call depend on dev->subordinate but left pci_slot_unlock() unmodified creating locking asymmetry compared with pci_slot_lock().

Because of the asymmetric lock handling, the same bridge device is unlocked twice. First pci_bus_unlock() unlocks bus->self and then pci_slot_unlock() will unconditionally unlock the same bridge device.

Quoted 6 lines

Move pci_dev_unlock() inside an else branch to match the logic in pci_slot_lock().

Fixes a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
Reviewed-by on v2 1/1
#2 lore raw
In reply to Ilpo Järvinen
Quoted 9 lines · Ilpo Järvinen

The commit a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") made the lock function to call depend on dev->subordinate but left pci_slot_unlock() unmodified creating locking asymmetry compared with pci_slot_lock().

Because of the asymmetric lock handling, the same bridge device is unlocked twice. First pci_bus_unlock() unlocks bus->self and then pci_slot_unlock() will unconditionally unlock the same bridge device.

Quoted 6 lines

Move pci_dev_unlock() inside an else branch to match the logic in pci_slot_lock().

Fixes a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
Quoted 25 lines

---

v2:
- Improve changelog (Lukas)
- Added Cc stable

 drivers/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/pci.c +2 -1
index 4d7c9f64ea24..26507aa906d7 100644
@@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
 			continue;
 		if (dev->subordinate)
 			pci_bus_unlock(dev->subordinate);
-		pci_dev_unlock(dev);
+		else
+			pci_dev_unlock(dev);
 	}
 }
 

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8

#3 lore raw
In reply to Ilpo Järvinen
Quoted 9 lines · Ilpo Järvinen

The commit a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") made the lock function to call depend on dev->subordinate but left pci_slot_unlock() unmodified creating locking asymmetry compared with pci_slot_lock().

Because of the asymmetric lock handling, the same bridge device is unlocked twice. First pci_bus_unlock() unlocks bus->self and then pci_slot_unlock() will unconditionally unlock the same bridge device.

Quoted 6 lines

Move pci_dev_unlock() inside an else branch to match the logic in pci_slot_lock().

Fixes a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")

Applied to pci/reset for v6.16, thanks!

Quoted 28 lines

---

v2:
- Improve changelog (Lukas)
- Added Cc stable

 drivers/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/pci.c +2 -1
index 4d7c9f64ea24..26507aa906d7 100644
@@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
 			continue;
 		if (dev->subordinate)
 			pci_bus_unlock(dev->subordinate);
-		pci_dev_unlock(dev);
+		else
+			pci_dev_unlock(dev);
 	}
 }
 

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8

Signature · 1 line
2.39.5