[Skiboot] [PATCH 8/8] Introduce memory allocation return value check

Samuel Mendoza-Jonas sam.mj at au1.ibm.com
Wed Jun 24 10:03:13 AEST 2015


On 23/06/15 18:37, Kamalesh Babulal wrote:
> In pci_std_swizzle_irq_map(), check if the memory allocation
> of interrupt-mask returns a valid pointer before using it.
> 
> Fixes Coverity defect#97854.
> 
> Signed-off-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
> ---
>  core/pci.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/core/pci.c b/core/pci.c
> index fe23d6c..ae71814 100644
> --- a/core/pci.c
> +++ b/core/pci.c
> @@ -1087,6 +1087,10 @@ void pci_std_swizzle_irq_map(struct dt_node *np,
>  	}
>  	map_size = esize * edevcount * 4 * sizeof(uint32_t);
>  	map = p = zalloc(map_size);
> +	if (!map) {
> +		prlog(PR_DEBUG, "Failed to allocate interrupt-map-mask !\n");
> +		goto fail;
> +	}
>  
>  	for (dev = 0; dev < edevcount; dev++) {
>  		for (irq = 0; irq < 4; irq++) {
> @@ -1111,7 +1115,9 @@ void pci_std_swizzle_irq_map(struct dt_node *np,
>  	}
>  
>  	dt_add_property(np, "interrupt-map", map, map_size);
> -	free(map);
> +fail:
> +	if (map)
> +		free(map);
>  }

All good but you don't need to do if(map) since free(NULL) is a noop.

Cheers,
Sam

>  
>  static void pci_add_slot_properties(struct phb *phb, struct pci_slot_info *info,
> 


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



More information about the Skiboot mailing list