Skip to contentSkip to conversation

Make pci_set_power_state() check register version

PATCH Applied David Howells 2 participants 2 messages Dec 17, 2004 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make pci_set_power_state() check register version

The attached patch makes pci_set_power_state() check the PM register version and ignore non-version 2 registers. Trampling on earlier version PM registers such as are sported by the Promise 20269 IDE card can cause the system to hang.

---
warthog>diffstat pci-pm-2610rc3mm1.diff

 pci.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/pci/pci.c +9 -3
diff -uNrp linux-2.6.10-rc3-mm1-asmoffsets/drivers/pci/pci.c linux-2.6.10-rc3-mm1-debug/drivers/pci/pci.c
@@ -245,7 +245,7 @@ int
 pci_set_power_state(struct pci_dev *dev, int state)
 {
 	int pm;
-	u16 pmcsr;
+	u16 pmcsr, pmc;
 
 	/* bound the state we're entering */
 	if (state > 3) state = 3;
@@ -265,10 +265,16 @@ pci_set_power_state(struct pci_dev *dev,
 	/* abort if the device doesn't support PM capabilities */
 	if (!pm) return -EIO; 
 
+	pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
+	if ((pmc & PCI_PM_CAP_VER_MASK) != 2) {
+		printk(KERN_WARNING
+		       "PCI: %s has unsupported PM cap regs version (%u)\n",
+		       dev->slot_name, pmc & PCI_PM_CAP_VER_MASK);
+		return -EIO;
+	}
+
 	/* check if this device supports the desired state */
 	if (state == 1 || state == 2) {
-		u16 pmc;
-		pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
 		if (state == 1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
 		else if (state == 2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
 	}
Applied
#1 lore raw
Quoted 7 lines · David Howells

The attached patch makes pci_set_power_state() check the PM register version and ignore non-version 2 registers. Trampling on earlier version PM registers such as are sported by the Promise 20269 IDE card can cause the system to hang.

Applied, thanks.

greg k-h