[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMbhsRTczY7zwCAYtrXm9EsfT+BLnJy_rnbf35cFOQ_303ODCA@mail.gmail.com>
Date: Mon, 16 Dec 2013 23:26:02 -0800
From: Colin Cross <ccross@...roid.com>
To: John Stultz <john.stultz@...aro.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Greg KH <gregkh@...uxfoundation.org>,
Android Kernel Team <kernel-team@...roid.com>,
kbuild test robot <fengguang.wu@...el.com>
Subject: Re: [PATCH 2/3] staging: ion: Fix possible null pointer dereference
On Mon, Dec 16, 2013 at 9:07 PM, John Stultz <john.stultz@...aro.org> 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 checks the return for NULL, and reworks the logic, as
> suggested by Colin, so we allocate the page_info structure first.
>
> Cc: Colin Cross <ccross@...roid.com>
> Cc: Greg KH <gregkh@...uxfoundation.org>
> Cc: Android Kernel Team <kernel-team@...roid.com>
> Cc: kbuild test robot <fengguang.wu@...el.com>
> Reported-by: kbuild test robot <fengguang.wu@...el.com>
> Signed-off-by: John Stultz <john.stultz@...aro.org>
> ---
> drivers/staging/android/ion/ion_system_heap.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index 144b2272..7f07291 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -108,6 +108,10 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
> struct page_info *info;
> int i;
>
> + info = kmalloc(sizeof(struct page_info), GFP_KERNEL);
> + if (!info)
> + return NULL;
> +
> for (i = 0; i < num_orders; i++) {
> if (size < order_to_size(orders[i]))
> continue;
> @@ -118,11 +122,12 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
> if (!page)
> continue;
>
> - info = kmalloc(sizeof(struct page_info), GFP_KERNEL);
> info->page = page;
> info->order = orders[i];
> return info;
> }
> + kfree(info);
> +
> return NULL;
> }
>
Acked-by: Colin Cross <ccross@...roid.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists