[PATCH v3 2/2] staging: android: Remove BUG from ion_system_heap.c
From: Tomer Samara
Date: Wed Aug 19 2020 - 15:39:45 EST
Remove BUG() at ion_sytem_heap.c and error handling to:
- free_buffer_page
- alloc_buffer_page
this fix the following checkpatch issue:
Avoid crashing the kernel - try using WARN_ON &
recovery code ratherthan BUG() or BUG_ON().
Signed-off-by: Tomer Samara <tomersamara98@xxxxxxxxx>
---
drivers/staging/android/ion/ion_system_heap.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index eac0632ab4e8..56d53268b82c 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -30,7 +30,7 @@ static int order_to_index(unsigned int order)
for (i = 0; i < NUM_ORDERS; i++)
if (order == orders[i])
return i;
- BUG();
+
return -1;
}
@@ -48,8 +48,13 @@ static struct page *alloc_buffer_page(struct ion_system_heap *heap,
struct ion_buffer *buffer,
unsigned long order)
{
- struct ion_page_pool *pool = heap->pools[order_to_index(order)];
+ struct ion_page_pool *pool;
+ int index = order_to_index(order);
+ if (index < 0)
+ return NULL;
+
+ pool = heap->pools[index];
return ion_page_pool_alloc(pool);
}
@@ -58,6 +63,7 @@ static void free_buffer_page(struct ion_system_heap *heap,
{
struct ion_page_pool *pool;
unsigned int order = compound_order(page);
+ int index;
/* go to system */
if (buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE) {
@@ -65,8 +71,11 @@ static void free_buffer_page(struct ion_system_heap *heap,
return;
}
- pool = heap->pools[order_to_index(order)];
+ index = order_to_index(order);
+ if (index < 0)
+ return;
+ pool = heap->pools[index];
ion_page_pool_free(pool, page);
}
--
2.25.1