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

Gavin Shan gwshan at linux.vnet.ibm.com
Wed Jun 24 09:56:14 AEST 2015


On Tue, Jun 23, 2015 at 02:07:35PM +0530, Kamalesh Babulal wrote:
>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;
>+

I think the check can be dropped. I don't see this function is called
with NULL phb/pd.

>+	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;

Thanks,
Gavin



More information about the Skiboot mailing list