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

Kamalesh Babulal kamalesh at linux.vnet.ibm.com
Wed Jun 24 16:09:52 AEST 2015



On 06/24/2015 05:36 AM, Gavin Shan wrote:
> On Tue, Jun 23, 2015 at 02:07:38PM +0530, 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;
>> +	}
> If the memory chunk can't be allocated, we needn't try to free it
> with check.
>
>> 	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);
> The free() won't be called for ever.
>
>

Thanks for the review. Will repost the patch.

-- 
Cheers,
Kamalesh.



More information about the Skiboot mailing list