diff mbox

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

Message ID 1387229564-19517-3-git-send-email-john.stultz@linaro.org
State Changes Requested
Headers show

Commit Message

John Stultz Dec. 16, 2013, 9:32 p.m. UTC
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.

Cc: Colin Cross <ccross@android.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Android Kernel Team <kernel-team@android.com>
Cc: kbuild test robot <fengguang.wu@intel.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/staging/android/ion/ion_system_heap.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 144b2272..cc2e4da 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -119,6 +119,11 @@  static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
 			continue;
 
 		info = kmalloc(sizeof(struct page_info), GFP_KERNEL);
+		if(!info) {
+			free_buffer_page(heap, buffer, page, orders[i]);
+			continue;
+		}
+
 		info->page = page;
 		info->order = orders[i];
 		return info;