From aadb9ac89c8fb8c29f41ea24a22c1ce5ac9bfc16 Mon Sep 17 00:00:00 2001 From: Prakash Gupta Date: Wed, 22 Mar 2017 18:52:45 +0530 Subject: [PATCH] ion: ion_system_heap: Fix null pointer dereference The pointer returned from alloc_pages passed unchecked to ion_pages_sync_for_device. This patch checks the return for NULL. Change-Id: I407efc73a1e1297f382a7926cc79542bde88d06d Fixes: 2d4fdc7bde46 ("ion: Fix DMA operations for ARM64") Signed-off-by: Prakash Gupta --- drivers/staging/android/ion/ion_system_heap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 03b2b8a38991..2ad4cc7a4785 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -2,7 +2,7 @@ * drivers/staging/android/ion/ion_system_heap.c * * Copyright (C) 2011 Google, Inc. - * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -123,9 +123,11 @@ static struct page *alloc_buffer_page(struct ion_system_heap *heap, gfp_t gfp_mask = low_order_gfp_flags; if (order) gfp_mask = high_order_gfp_flags; + page = alloc_pages(gfp_mask, order); - ion_pages_sync_for_device(dev, page, PAGE_SIZE << order, - DMA_BIDIRECTIONAL); + if (page) + ion_pages_sync_for_device(dev, page, PAGE_SIZE << order, + DMA_BIDIRECTIONAL); } if (!page) return 0;