[Skiboot] [PATCH 5/8] pci_configure_mps(): Check empty pointer before dereferencing

Kamalesh Babulal kamalesh at linux.vnet.ibm.com
Tue Jun 23 18:37:35 AEST 2015


Re-arrange the code in pci_configure_mps() to avoid dereferencing
of in-valid pointer.

Fixes Coverity defect#97851.

Signed-off-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
---
 core/pci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/core/pci.c b/core/pci.c
index 8f8aeeb..fe23d6c 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -611,14 +611,15 @@ static int pci_configure_mps(struct phb *phb,
 	uint32_t ecap, mps = phb->mps;
 	uint16_t val;
 
+	if (!phb || !pd)
+		return 0;
+
+	mps = phb->mps;
 	/* If the MPS isn't acceptable one, bail immediately */
 	if (mps < 128 || mps > 4096)
 		return 1;
 
-	if (!phb || !pd)
-		return 0;
-
-	/* PCIe deivce always has MPS capacity */
+	/* PCIe device always has MPS capacity */
 	if (pd->mps) {
 		ecap = pci_cap(pd, PCI_CFG_CAP_ID_EXP, false);
 		mps = ilog2(mps) - 7;
-- 
2.1.2



More information about the Skiboot mailing list