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

Samuel Mendoza-Jonas sam.mj at au1.ibm.com
Wed Jun 24 09:54:35 AEST 2015


On 23/06/15 18:37, 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;

You should also avoid initialising mps here in case phb is NULL,
especially since you're assigning it down...

>  	uint16_t val;
>  
> +	if (!phb || !pd)
> +		return 0;
> +
> +	mps = phb->mps;

...here anyway.

Cheers,
Sam

>  	/* 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;
> 


-- 
-----------
LTC Ozlabs
IBM



More information about the Skiboot mailing list