[PATCH v5 0/2] staging: android: Remove BUG/BUG_ON

2020-08-23 Thread Tomer Samara
Remove BUG/BUG_ON from androind/ion

-v5:
remove WARN_ON from ion_page_pool_free

-v4:
some changes based on Dan Carpenter review:
- Remove error check at ion_page_pool_remove (conditions are impossible)
- Remove error check at opn_page_pool_alloc
- restore WARN_ON at ion_page_pool_free
- Remove unnecessary error check at ion_page_pool_shrink
- Add /* This is impossible. */ comment at order_to_index
- Remove error handling of order_to_index

-v3:
remove WARN/WARN_ON as Gerg KH suggests

-v2: 
add error check to order_to_index callers

Tomer Samara (2):
  staging: android: Remove BUG_ON from ion_page_pool.c
  staging: android: Remove BUG from ion_system_heap.c

 drivers/staging/android/ion/ion_page_pool.c   | 6 --
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 2 files changed, 1 insertion(+), 7 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v5 2/2] staging: android: Remove BUG from ion_system_heap.c

2020-08-23 Thread Tomer Samara
Remove BUG() from 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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c 
b/drivers/staging/android/ion/ion_system_heap.c
index eac0632ab4e8..00d6154aec34 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();
+   /* This is impossible. */
return -1;
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v4 2/2] staging: android: Remove BUG from ion_system_heap.c

2020-08-23 Thread Tomer Samara
On Fri, Aug 21, 2020 at 09:25:26AM -0700, Randy Dunlap wrote:
> On 8/21/20 8:28 AM, Tomer Samara wrote:
> > Remove BUG() from 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().
> > 
> > Signed-off-by: Tomer Samara 
> > ---
> >  drivers/staging/android/ion/ion_system_heap.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/android/ion/ion_system_heap.c 
> > b/drivers/staging/android/ion/ion_system_heap.c
> > index eac0632ab4e8..00d6154aec34 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();
> > +   /* This is impossible. */
> > return -1;
> >  }
> 
> Hi,
> Please explain why this is impossible.
> 
> If some caller calls order_to_index(5), it will return -1, yes?
> 
> -- 
> ~Randy
> 

As Dan Carpenter says here 
https://lkml.kernel.org/lkml/cover.1597865771.git.tomersamar...@gmail.com/T/#mc790b91029565b1bb0cb87997b39007d9edb6e04.
After looking at callers we see that order_to_index called from 2 functions:
- alloc_buffer_page called from alloc_largest_available which 
  loop over all legit order nubmers
  ( Flow:
   alloc_largest_available-->alloc_buffer_page-->order_to_index
  )

- free_buffer_page takes the order using compound_order, which return 0 or
  the order number for the page, this function has 2 callers too,
  ion_system_heap_allocate (which called it in case of failure at 
sg_alloc_table,
  thus calling from this flow will no casue error) and ion_system_heap_free
  (which will be called on every sg table in the buffer that allocated good,
  meaning from this flow also error will not be created).
  ( Flows:
   ion_system_heap_free --> free_buffer_page --> order_to_index
   ion_system_heap_allocate --> free_buffer_page --> order_to_index
  )

Of course if some user will use this function with wrong order number he will 
be able to get this -1.
So should I remove this comment and resotre the error checks?
Btw, this is the same reason that I dropped the error check at 
ion_page_pool_shrink, so should I restore here also?

Thanks,
Tomer Samara

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v5 1/2] staging: android: Remove BUG_ON from ion_page_pool.c

2020-08-23 Thread Tomer Samara
BUG_ON() is removed at ion_page_pool.c

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

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 0198b886d906..fa764299f004 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -46,11 +46,9 @@ static struct page *ion_page_pool_remove(struct 
ion_page_pool *pool, bool high)
struct page *page;
 
if (high) {
-   BUG_ON(!pool->high_count);
page = list_first_entry(&pool->high_items, struct page, lru);
pool->high_count--;
} else {
-   BUG_ON(!pool->low_count);
page = list_first_entry(&pool->low_items, struct page, lru);
pool->low_count--;
}
@@ -65,8 +63,6 @@ struct page *ion_page_pool_alloc(struct ion_page_pool *pool)
 {
struct page *page = NULL;
 
-   BUG_ON(!pool);
-
mutex_lock(&pool->mutex);
if (pool->high_count)
page = ion_page_pool_remove(pool, true);
@@ -82,8 +78,6 @@ 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));
-
ion_page_pool_add(pool, page);
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v4 2/2] staging: android: Remove BUG from ion_system_heap.c

2020-08-22 Thread Tomer Samara
Remove BUG() from 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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c 
b/drivers/staging/android/ion/ion_system_heap.c
index eac0632ab4e8..00d6154aec34 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();
+   /* This is impossible. */
return -1;
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v4 0/2] staging: android: Remove BUG/BUG_ON from ion

2020-08-22 Thread Tomer Samara
Remove BUG/BUG_ON from androind/ion


-v4:
some changes based on Dan Carpenter review:
- Remove error check at ion_page_pool_remove (conditions are impossible)
- Remove error check at opn_page_pool_alloc
- restore WARN_ON at ion_page_pool_free
- Remove unnecessary error check at ion_page_pool_shrink
- Add /* This is impossible. */ comment at order_to_index
- Remove error handling of order_to_index

-v3:
remove WARN/WARN_ON as Gerg KH suggests

-v2: 
add error check to order_to_index callers

Tomer Samara (2):
  staging: android: Remove BUG_ON from ion_page_pool.c
  staging: android: Remove BUG from ion_system_heap.c

 drivers/staging/android/ion/ion_page_pool.c   | 6 +-
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v4 1/2] staging: android: Remove BUG_ON from ion_page_pool.c

2020-08-22 Thread Tomer Samara
BUG_ON() is removed at ion_page_pool.c

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

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 0198b886d906..a3ed3bfd47ee 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -46,11 +46,9 @@ static struct page *ion_page_pool_remove(struct 
ion_page_pool *pool, bool high)
struct page *page;
 
if (high) {
-   BUG_ON(!pool->high_count);
page = list_first_entry(&pool->high_items, struct page, lru);
pool->high_count--;
} else {
-   BUG_ON(!pool->low_count);
page = list_first_entry(&pool->low_items, struct page, lru);
pool->low_count--;
}
@@ -65,8 +63,6 @@ struct page *ion_page_pool_alloc(struct ion_page_pool *pool)
 {
struct page *page = NULL;
 
-   BUG_ON(!pool);
-
mutex_lock(&pool->mutex);
if (pool->high_count)
page = ion_page_pool_remove(pool, true);
@@ -82,7 +78,7 @@ 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));
+   WARN_ON(pool->order != compound_order(page))
 
ion_page_pool_add(pool, page);
 }
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3 0/2] staging: android: Remove BUG/BUG_ONs

2020-08-20 Thread Tomer Samara
Remove BUG/BUG_ONs from androind/ion allocator and add error handling to
calling functions

Tomer Samara (2):
  staging: android: Remove BUG_ON from ion_page_pool.c
  staging: android: Remove BUG from ion_system_heap.c

 drivers/staging/android/ion/ion_page_pool.c   | 14 ++
 drivers/staging/android/ion/ion_system_heap.c | 15 ---
 2 files changed, 22 insertions(+), 7 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3 0/2] staging: android: Remove BUG/BUG_ON from ion

2020-08-20 Thread Tomer Samara
Removeing BUG/BUG_ON from androind/ion and add error handle to calling
functions

Tomer Samara (2):
  staging: android: Remove BUG_ON from ion_page_pool.c
  staging: android: Remove BUG from ion_system_heap.c

 drivers/staging/android/ion/ion_page_pool.c   | 14 ++
 drivers/staging/android/ion/ion_system_heap.c | 15 ---
 2 files changed, 22 insertions(+), 7 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3 1/2] staging: android: Remove BUG_ON from ion_page_pool.c

2020-08-20 Thread Tomer Samara
BUG_ON() is removed at ion_page_pool.c and add error handleing to
ion_page_pool_shrink

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

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 0198b886d906..ae2bc57bcbe8 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -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 (!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 (!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 (!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 (pool->order != compound_order(page))
+   return;
 
ion_page_pool_add(pool, page);
 }
@@ -124,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);
}
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3 2/2] staging: android: Remove BUG from ion_system_heap.c

2020-08-20 Thread Tomer Samara
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 
---
 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

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 0/4] *** SUBJECT HERE ***

2020-08-18 Thread Tomer Samara
On Tue, Aug 18, 2020 at 11:50:35AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Aug 18, 2020 at 12:17:08PM +0300, Tomer Samara wrote:
> > *** BLURB HERE ***
> 
> Really?
> 
> And your subject line could use some work too :(
>

sorry for that, i've made a script for sending patchset and accidently 
it sents mails without contorl.
Fixed that
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

2020-08-18 Thread Tomer Samara
On Tue, Aug 18, 2020 at 04:11:06PM +0200, Greg Kroah-Hartman wrote:
> On Sun, Aug 16, 2020 at 10:23:25PM +0300, Tomer Samara wrote:
> > BUG_ON() is replaced with WARN_ON at ion_page_pool.c
> 
> Why?
> 
> > 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?

> > 
> > Signed-off-by: Tomer Samara 
> > ---
> >  drivers/staging/android/ion/ion_page_pool.c | 12 
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/android/ion/ion_page_pool.c 
> > b/drivers/staging/android/ion/ion_page_pool.c
> > index 0198b886d906..c1b9eda35c96 100644
> > --- a/drivers/staging/android/ion/ion_page_pool.c
> > +++ b/drivers/staging/android/ion/ion_page_pool.c
> > @@ -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

Will do :)
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 3/3] staging: androind: Convert BUG() to WARN()

2020-08-17 Thread 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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_system_heap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c 
b/drivers/staging/android/ion/ion_system_heap.c
index eac0632ab4e8..37065a59ca69 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -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;
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 1/3] staging: androind: Replace BUG_ONs with WARN_ONs

2020-08-17 Thread Tomer Samara
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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 0198b886d906..4acc0eebf781 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -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);
 }
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

2020-08-17 Thread Tomer Samara
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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 0198b886d906..c1b9eda35c96 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -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);
 }
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 0/3] Replac BAG/BAG_ON with WARN/WARN_ON

2020-08-17 Thread Tomer Samara
This series convert BUGs/BUG_ONs to WARNs/WARN_ONs

Tomer Samara (3):
  staging: androind: Replace BUG_ONs with WARN_ONs
  staging: androind: Add error handling to ion_page_pool_shrink
  staging: androind: Convert BUG() to WARN()

 drivers/staging/android/ion/ion_page_pool.c   | 14 ++
 drivers/staging/android/ion/ion_system_heap.c |  3 ++-
 2 files changed, 12 insertions(+), 5 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 3/3] staging: androind: Convert BUG() to WARN()

2020-08-17 Thread Tomer Samara
On Sun, Aug 16, 2020 at 10:34:50AM -0700, Randy Dunlap wrote:
> On 8/16/20 10:22 AM, Tomer Samara wrote:
> > 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().
> > 
> > Signed-off-by: Tomer Samara 
> > ---
> >  drivers/staging/android/ion/ion_system_heap.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/android/ion/ion_system_heap.c 
> > b/drivers/staging/android/ion/ion_system_heap.c
> > index eac0632ab4e8..37065a59ca69 100644
> > --- a/drivers/staging/android/ion/ion_system_heap.c
> > +++ b/drivers/staging/android/ion/ion_system_heap.c
> > @@ -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;
> >  }
> 
> Hi,
> Did you look at what happens when order_to_index() returns -1
> to its callers?
> 
> 
> Also: fix spelling in Subjects: android and BUG/BUG_ON
> 
> -- 
> ~Randy
> 

Hi,
yes I've made a patch for that too but it seems I forgot to
include him in the patch set.
I will send new version for this patch set soon.

Thanks
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 2/3] staging: androind: Add error handling to ion_page_pool_shrink

2020-08-17 Thread Tomer Samara
Add error check to ion_page_pool_shrink after calling
ion_page_pool_remove, due to converting BUG_ON to WARN_ON.

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index 4acc0eebf781..c61548ecf7f2 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -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);
}
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 0/4] Replace BUG/BUG_ON to WARN/WARN_ON

2020-08-17 Thread Tomer Samara


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(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

2020-08-17 Thread 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().

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_system_heap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c 
b/drivers/staging/android/ion/ion_system_heap.c
index eac0632ab4e8..37065a59ca69 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -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;
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

2020-08-17 Thread Tomer Samara
Add error check to ion_page_pool_shrink after calling
ion_page_pool_remove, due to converting BUG_ON to WARN_ON.

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_page_pool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/android/ion/ion_page_pool.c 
b/drivers/staging/android/ion/ion_page_pool.c
index c1b9eda35c96..031550473000 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -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);
}
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

2020-08-17 Thread 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.

Signed-off-by: Tomer Samara 
---
 drivers/staging/android/ion/ion_system_heap.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/ion/ion_system_heap.c 
b/drivers/staging/android/ion/ion_system_heap.c
index 37065a59ca69..1e73bfc4 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -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);
 }
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel