Message ID | 39222c3a041708c41ab3bc1be855ac83912ee07b.1597865771.git.tomersamara98@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | staging: android: Remove BUG/BUG_ONs | expand |
On Wed, Aug 19, 2020 at 10:39:34PM +0300, Tomer Samara wrote: > 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@gmail.com> > --- > 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; > } Just delete the BUG() and put a comment that /* This is impossible. */ so that reviewers know that we never return -1. I suspect that there are some static analysis tools which might complain about this -1 return. But those tools are pretty crap. Never change code just to make the tools happy. regards, dan carpenter
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); }
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@gmail.com> --- drivers/staging/android/ion/ion_system_heap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)