Skip to contentSkip to conversation

Replace BUG/BUG_ON to WARN/WARN_ON

PATCH In review Tomer Samara 2 participants 11 messages Aug 16, 2020 – Aug 18, 2020 Staging

lore
Share & tools
lore
#0 lore raw

v2 cover Replace BUG/BUG_ON to WARN/WARN_ON

This series convert BUGs/BUG_ONs to WARNs/WARN_ONs

Tomer Samara (4):
staging: android: Replace BUG_ON with WARN_ON
staging: android: Add error handling to ion_page_pool_shrink
staging: android: Convert BUG to WARN
staging: android: Add error handling to order_to_index callers

 drivers/staging/android/ion/ion_page_pool.c   | 14 ++++++++++----
 drivers/staging/android/ion/ion_system_heap.c | 16 +++++++++++++---
 2 files changed, 23 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 staging: android: Replace BUG_ON with WARN_ON

BUG_ON() is replaced with WARN_ON at ion_page_pool.c
Fixes the following issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

---
 drivers/staging/android/ion/ion_page_pool.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/android/ion/ion_page_pool.c +8 -4
index 0198b886d906..c1b9eda35c96 100644
@@ -46,11 +46,13 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high)
 	struct page *page;
 
 	if (high) {
-		BUG_ON(!pool->high_count);
+		if (WARN_ON(!pool->high_count))
+			return NULL;
 		page = list_first_entry(&pool->high_items, struct page, lru);
 		pool->high_count--;
 	} else {
-		BUG_ON(!pool->low_count);
+		if (WARN_ON(!pool->low_count))
+			return NULL;
 		page = list_first_entry(&pool->low_items, struct page, lru);
 		pool->low_count--;
 	}
@@ -65,7 +67,8 @@ struct page *ion_page_pool_alloc(struct ion_page_pool *pool)
 {
 	struct page *page = NULL;
 
-	BUG_ON(!pool);
+	if (WARN_ON(!pool))
+		return NULL;
 
 	mutex_lock(&pool->mutex);
 	if (pool->high_count)
@@ -82,7 +85,8 @@ struct page *ion_page_pool_alloc(struct ion_page_pool *pool)
 
 void ion_page_pool_free(struct ion_page_pool *pool, struct page *page)
 {
-	BUG_ON(pool->order != compound_order(page));
+	if (WARN_ON(pool->order != compound_order(page)))
+		return;
 
 	ion_page_pool_add(pool, page);
 }
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 2/4 staging: android: Add error handling to ion_page_pool_shrink

In reply to Tomer Samara

Add error check to ion_page_pool_shrink after calling ion_page_pool_remove, due to converting BUG_ON to WARN_ON.

---
 drivers/staging/android/ion/ion_page_pool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/android/ion/ion_page_pool.c +2 -0
index c1b9eda35c96..031550473000 100644
@@ -128,6 +128,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
 			break;
 		}
 		mutex_unlock(&pool->mutex);
+		if (!page)
+			break;
 		ion_page_pool_free_pages(pool, page);
 		freed += (1 << pool->order);
 	}
Signature · 1 line
2.25.1
#7 lore raw

PATCH v2 3/4 staging: android: Convert BUG to WARN

In reply to Tomer Samara

replace BUG() with WARN() at ion_sytem_heap.c, this fix the following checkpatch issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

---
 drivers/staging/android/ion/ion_system_heap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_system_heap.c +2 -1
index eac0632ab4e8..37065a59ca69 100644
@@ -30,7 +30,8 @@ static int order_to_index(unsigned int order)
 	for (i = 0; i < NUM_ORDERS; i++)
 		if (order == orders[i])
 			return i;
-	BUG();
+
+	WARN(1, "%s: Did not found index to order %d", __FUNCTION__, order);
 	return -1;
 }
 
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 4/4 staging: android: Add error handling to order_to_index callers

In reply to Tomer Samara

Add error check to:
- free_buffer_page
- alloc_buffer_page
after calling order_to_index, due to converting BUG to WARN at order_to_index.

---
 drivers/staging/android/ion/ion_system_heap.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/staging/android/ion/ion_system_heap.c +11 -2
index 37065a59ca69..1e73bfc88884 100644
@@ -49,8 +49,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);
 }
 
@@ -59,6 +64,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) {
@@ -66,8 +72,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);
 }
 
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v2 2/4] staging: android: Add error handling to ion_page_pool_shrink

In reply to Tomer Samara
Quoted 4 lines · Tomer Samara

Add error check to ion_page_pool_shrink after calling ion_page_pool_remove, due to converting BUG_ON to WARN_ON.

So this fixes a previous patch? That's not good, please merge them together so you do not cause a bug and then fix it up later on.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Re: [PATCH v2 1/4] staging: android: Replace BUG_ON with WARN_ON

In reply to Tomer Samara
Quoted 1 line · Tomer Samara

BUG_ON() is replaced with WARN_ON at ion_page_pool.c

Why?

Quoted 2 lines

Fixes the following issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

Ideally you can get rid of WARN_ON() too, right?

Many systems run in panic-on-warn mode, so this really does not change anything. Try fixing this up properly to not crash at all.

Quoted 11 lines
---
 drivers/staging/android/ion/ion_page_pool.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/android/ion/ion_page_pool.c +0 -0
index 0198b886d906..c1b9eda35c96 100644

drivers/staging/android/ion/ion_page_pool.c static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) · line 50

Quoted 6 lines
drivers/staging/android/ion/ion_page_pool.c +2 -1
@@ -46,11 +46,13 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high)
 	struct page *page;
 
 	if (high) {
-		BUG_ON(!pool->high_count);
+		if (WARN_ON(!pool->high_count))
+			return NULL;

And can you test this that it works properly?

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Re: [PATCH v2 3/4] staging: android: Convert BUG to WARN

In reply to Tomer Samara
Quoted 15 lines · Tomer Samara

replace BUG() with WARN() at ion_sytem_heap.c, this fix the following checkpatch issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

---
 drivers/staging/android/ion/ion_system_heap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_system_heap.c +0 -0
index eac0632ab4e8..37065a59ca69 100644

drivers/staging/android/ion/ion_system_heap.c static int order_to_index(unsigned int order) · line 34

Quoted 6 lines
drivers/staging/android/ion/ion_system_heap.c +2 -1
@@ -30,7 +30,8 @@ static int order_to_index(unsigned int order)
 	for (i = 0; i < NUM_ORDERS; i++)
 		if (order == orders[i])
 			return i;
-	BUG();
+
+	WARN(1, "%s: Did not found index to order %d", __FUNCTION__, order);

Same question as before, I think this didn't really change anything :(

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

Re: [PATCH v2 4/4] staging: android: Add error handling to order_to_index callers

In reply to Tomer Samara
Quoted 5 lines · Tomer Samara

Add error check to:
- free_buffer_page
- alloc_buffer_page
after calling order_to_index, due to converting BUG to WARN at order_to_index.

You are fixing a bug you caused in a previous patch, not good :)

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH v2 1/4] staging: android: Replace BUG_ON with WARN_ON

In reply to Greg Kroah-Hartman
Quoted 5 lines · Greg Kroah-Hartman
Quoted 1 line · Tomer Samara

BUG_ON() is replaced with WARN_ON at ion_page_pool.c

Why?

Quoted 8 lines
Quoted 2 lines

Fixes the following issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

Ideally you can get rid of WARN_ON() too, right?

Many systems run in panic-on-warn mode, so this really does not change anything. Try fixing this up properly to not crash at all.

You mean by that to just remove the WARN_ON and leave the condition the same?

Quoted 20 lines
Quoted 11 lines
---
 drivers/staging/android/ion/ion_page_pool.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/android/ion/ion_page_pool.c +0 -0
index 0198b886d906..c1b9eda35c96 100644

drivers/staging/android/ion/ion_page_pool.c static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) · line 50

Quoted 6 lines
drivers/staging/android/ion/ion_page_pool.c +2 -1
@@ -46,11 +46,13 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high)
 	struct page *page;
 
 	if (high) {
-		BUG_ON(!pool->high_count);
+		if (WARN_ON(!pool->high_count))
+			return NULL;

And can you test this that it works properly?

Quoted 3 lines

thanks,

greg k-h

Will do :)

#4 lore raw

Re: [PATCH v2 1/4] staging: android: Replace BUG_ON with WARN_ON

Quoted 9 lines · Tomer Samara
Quoted 8 lines · Greg Kroah-Hartman
Quoted 1 line · Tomer Samara

BUG_ON() is replaced with WARN_ON at ion_page_pool.c

Why?

Quoted 2 lines

Fixes the following issue:
Avoid crashing the kernel - try using WARN_ON & recovery code ratherthan BUG() or BUG_ON().

Quoted 7 lines
Quoted 5 lines

Ideally you can get rid of WARN_ON() too, right?

Many systems run in panic-on-warn mode, so this really does not change anything. Try fixing this up properly to not crash at all.

You mean by that to just remove the WARN_ON and leave the condition the same?

Or fix the problem that could ever cause this check to fire.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel