diff mbox

pci: avoid unnecessary writing of the command register during probe

Message ID 1377209958-26362-1-git-send-email-zoltan.kiss@citrix.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Zoltan Kiss Aug. 22, 2013, 10:19 p.m. UTC
While I tracked an another bug, I noticed that the PCI command register is
quite often updated here unnecessarily.

Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
---
 drivers/pci/probe.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 46ada5c..54f6bec 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -178,8 +178,12 @@  int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	/* No printks while decoding is disabled! */
 	if (!dev->mmio_always_on) {
 		pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
-		pci_write_config_word(dev, PCI_COMMAND,
-			orig_cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+		if (orig_cmd & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)) {
+			pci_write_config_word(dev,
+				PCI_COMMAND,
+				orig_cmd &
+				~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+		}
 	}
 
 	res->name = pci_name(dev);
@@ -293,7 +297,8 @@  int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 fail:
 	res->flags = 0;
 out:
-	if (!dev->mmio_always_on)
+	if (!dev->mmio_always_on &&
+		(orig_cmd & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
 		pci_write_config_word(dev, PCI_COMMAND, orig_cmd);
 
 	if (bar_too_big)