Re: [RFC][PATCH 2/3] staging: ion: Fix possible null pointer dereference

From: John Stultz
Date: Mon Dec 16 2013 - 19:37:20 EST


On 12/16/2013 04:26 PM, Colin Cross wrote:
> On Mon, Dec 16, 2013 at 1:32 PM, John Stultz <john.stultz@xxxxxxxxxx> wrote:
>> The kbuild test robot reported:
>>
>> drivers/staging/android/ion/ion_system_heap.c:122 alloc_largest_available() error: potential null dereference 'info'. (kmalloc returns null)
>>
>> Where the pointer returned from kmalloc goes unchecked for failure.
>>
>> This patch adds a simple check for a null return, and handles the error.
>>
>> XXX: Not sure if continue or 'return NULL' is the right thing to do.
> Returning NULL is fine, there is no reason the kmalloc is going to
> succeed if it retries, and it will just have to allocate more of them
> if it starts fulfilling the allocation with smaller order chunks.
>
> Allocating the struct before entering the loop might make error handling easier.

Ok, I had actually done that in my first pass, but then got worried the
allocation/free might have extra overhead in the case where the pool is
exhausted, so I stuck with the existing pattern. But if that's not a
common state, then I agree, it does make the handling simpler.

I'll rework this and re-submit. Thanks for the feedback!

thanks
-john
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/