diff mbox series

[1/6] PCI: don't clear already cleared bit

Message ID 20240709133610.1089420-2-stewart.hildebrand@amd.com (mailing list archive)
State Superseded
Delegated to: Bjorn Helgaas
Headers show
Series PCI: align small (<4k) BARs | expand

Commit Message

Stewart Hildebrand July 9, 2024, 1:35 p.m. UTC
pci_reassigndev_resource_alignment() performs a PCI config read, then
then unconditionally clears a bit and issues a PCI config write.
However, the bit in question (PCI_COMMAND_MEMORY) is a RW bit, so it is
unnecessary to issue the PCI config write if the bit is already cleared.
Make the write conditional.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
Should this be folded into ("pci: restore memory decoding after
reallocation") in this series?
---
 drivers/pci/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index df550953fa26..f017e7a8f028 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6632,8 +6632,10 @@  void pci_reassigndev_resource_alignment(struct pci_dev *dev)
 	}
 
 	pci_read_config_word(dev, PCI_COMMAND, &command);
-	command &= ~PCI_COMMAND_MEMORY;
-	pci_write_config_word(dev, PCI_COMMAND, command);
+	if (command & PCI_COMMAND_MEMORY) {
+		command &= ~PCI_COMMAND_MEMORY;
+		pci_write_config_word(dev, PCI_COMMAND, command);
+	}
 
 	for (i = 0; i <= PCI_ROM_RESOURCE; i++)
 		pci_request_resource_alignment(dev, i, align, resize);