diff mbox

PCI: correct static code analysis tool issue

Message ID 1343270051-5217-1-git-send-email-jdmason@kudzu.us (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Jon Mason July 26, 2012, 2:34 a.m. UTC
Coverity noticed that pcie_bus_configure_settings() can call
pcie_bus_configure_set() when "smpss" is uninitialized.  The smpss is
used to make the bus and all child devices have a uniform value.
Setting the smpss is moot for PCIE_BUS_PERFORMANCE, since it will be
determined dynamically based on the max size of the parent device and
the child device.  To avoid the erroneous detection of this issue, set
the smpss to 0.  Also, add a case statement to make clearer the possible
use cases and add a nice comment describing what is being done in the
PCIE_BUS_PERFORMANCE case.

Signed-off-by: Jon Mason <jdmason@kudzu.us>
---
 drivers/pci/probe.c |   32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6c143b4..e813846 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1567,21 +1567,33 @@  void pcie_bus_configure_settings(struct pci_bus *bus, u8 mpss)
 	if (!pci_is_pcie(bus->self))
 		return;
 
-	if (pcie_bus_config == PCIE_BUS_TUNE_OFF)
-		return;
-
-	/* FIXME - Peer to peer DMA is possible, though the endpoint would need
-	 * to be aware to the MPS of the destination.  To work around this,
-	 * simply force the MPS of the entire system to the smallest possible.
-	 */
-	if (pcie_bus_config == PCIE_BUS_PEER2PEER)
+	switch (pcie_bus_config) {
+	case PCIE_BUS_PERFORMANCE:
+		/* The smpss is used to make the bus and all child devices have
+		 * a uniform value.  Setting the smpss is moot for
+		 * "Performance", since it will be determined dynamically based
+		 * on the max size of the parent device and the child device.
+		 * However, not setting the smpss can result in static code
+		 * analysis tools erroniously reporting an issue.  To avoid
+		 * this, set the smpss to 0.
+		 */
+	case PCIE_BUS_PEER2PEER:
+		/* FIXME - Peer to peer DMA is possible, though the endpoint
+		 * would need to be aware to the MPS of the destination.  To
+		 * work around this, simply force the MPS of the entire system
+		 * to the smallest possible.
+		 */
 		smpss = 0;
-
-	if (pcie_bus_config == PCIE_BUS_SAFE) {
+		break;
+	case PCIE_BUS_SAFE:
 		smpss = mpss;
 
 		pcie_find_smpss(bus->self, &smpss);
 		pci_walk_bus(bus, pcie_find_smpss, &smpss);
+		break;
+	case PCIE_BUS_TUNE_OFF:
+	default:
+		return;
 	}
 
 	pcie_bus_configure_set(bus->self, &smpss);