Skip to contentSkip to conversation

mm/vmalloc: replace BUG_ON to a simple if statement

PATCH Applied Hyunmin Lee 5 participants 5 messages Feb 1, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 mm/vmalloc: replace BUG_ON to a simple if statement

As per the coding standards, in the event of an abnormal condition that should not occur under normal circumstances, the kernel should attempt recovery and proceed with execution, rather than halting the machine.

Specifically, in the alloc_vmap_area() function, use a simple if() instead of using BUG_ON() halting the machine.

---
v1->v2 : Add commit description
v2->v3 : Change WARN_ON() to if()
v3->v4 : Use only one if() for three conditions

---
 mm/vmalloc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmalloc.c +2 -3
index 74afa2208558..3b7e8856be35 100644
@@ -1587,9 +1587,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	int purged = 0;
 	int ret;
 
-	BUG_ON(!size);
-	BUG_ON(offset_in_page(size));
-	BUG_ON(!is_power_of_2(align));
+	if (unlikely(!size || offset_in_page(size) || !is_power_of_2(align)))
+		return ERR_PTR(-EINVAL);
 
 	if (unlikely(!vmap_initialized))
 		return ERR_PTR(-EBUSY);
Signature · 1 line
2.25.1
Reviewed-by on v4 1/1
#1 lore raw

Le 01/02/2023 à 12:51, Hyunmin Lee a écrit :

Quoted 7 lines

As per the coding standards, in the event of an abnormal condition that should not occur under normal circumstances, the kernel should attempt recovery and proceed with execution, rather than halting the machine.

Specifically, in the alloc_vmap_area() function, use a simple if() instead of using BUG_ON() halting the machine.

Quoted 8 lines
Quoted 24 lines

---
v1->v2 : Add commit description
v2->v3 : Change WARN_ON() to if()
v3->v4 : Use only one if() for three conditions

---
  mm/vmalloc.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmalloc.c +2 -3
index 74afa2208558..3b7e8856be35 100644
@@ -1587,9 +1587,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
  	int purged = 0;
  	int ret;
 
-	BUG_ON(!size);
-	BUG_ON(offset_in_page(size));
-	BUG_ON(!is_power_of_2(align));
+	if (unlikely(!size || offset_in_page(size) || !is_power_of_2(align)))
+		return ERR_PTR(-EINVAL);
 
  	if (unlikely(!vmap_initialized))
  		return ERR_PTR(-EBUSY);
Reviewed-by on v4 1/1
#2 lore raw
In reply to Hyunmin Lee
Quoted 29 lines · Hyunmin Lee

As per the coding standards, in the event of an abnormal condition that should not occur under normal circumstances, the kernel should attempt recovery and proceed with execution, rather than halting the machine.

Specifically, in the alloc_vmap_area() function, use a simple if() instead of using BUG_ON() halting the machine.

---
v1->v2 : Add commit description
v2->v3 : Change WARN_ON() to if()
v3->v4 : Use only one if() for three conditions

---
 mm/vmalloc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmalloc.c +0 -0
index 74afa2208558..3b7e8856be35 100644
@@ -1587,9 +1587,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	int purged = 0;

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 1594

Quoted 10 lines
mm/vmalloc.c +2 -3
 	int ret;
 
-	BUG_ON(!size);
-	BUG_ON(offset_in_page(size));
-	BUG_ON(!is_power_of_2(align));
+	if (unlikely(!size || offset_in_page(size) || !is_power_of_2(align)))
+		return ERR_PTR(-EINVAL);
 
 	if (unlikely(!vmap_initialized))
 		return ERR_PTR(-EBUSY);

Thanks!

Quoted 2 lines
Signature · 1 line
2.25.1

Regards,
Hyeonggon

Reviewed-by on v4 1/1
#3 lore raw
In reply to Hyunmin Lee
Quoted 7 lines · Hyunmin Lee

As per the coding standards, in the event of an abnormal condition that should not occur under normal circumstances, the kernel should attempt recovery and proceed with execution, rather than halting the machine.

Specifically, in the alloc_vmap_area() function, use a simple if() instead of using BUG_ON() halting the machine.

Quoted 8 lines
Quoted 27 lines

---
v1->v2 : Add commit description
v2->v3 : Change WARN_ON() to if()
v3->v4 : Use only one if() for three conditions

---
 mm/vmalloc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmalloc.c +2 -3
index 74afa2208558..3b7e8856be35 100644
@@ -1587,9 +1587,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	int purged = 0;
 	int ret;
 
-	BUG_ON(!size);
-	BUG_ON(offset_in_page(size));
-	BUG_ON(!is_power_of_2(align));
+	if (unlikely(!size || offset_in_page(size) || !is_power_of_2(align)))
+		return ERR_PTR(-EINVAL);
 
 	if (unlikely(!vmap_initialized))
 		return ERR_PTR(-EBUSY);
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
maintainer Reviewed-by on v4 1/1
#4 lore raw
In reply to Hyunmin Lee
Quoted 42 lines · Hyunmin Lee

As per the coding standards, in the event of an abnormal condition that should not occur under normal circumstances, the kernel should attempt recovery and proceed with execution, rather than halting the machine.

Specifically, in the alloc_vmap_area() function, use a simple if() instead of using BUG_ON() halting the machine.

---
v1->v2 : Add commit description
v2->v3 : Change WARN_ON() to if()
v3->v4 : Use only one if() for three conditions

---
 mm/vmalloc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/vmalloc.c +2 -3
index 74afa2208558..3b7e8856be35 100644
@@ -1587,9 +1587,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	int purged = 0;
 	int ret;
 
-	BUG_ON(!size);
-	BUG_ON(offset_in_page(size));
-	BUG_ON(!is_power_of_2(align));
+	if (unlikely(!size || offset_in_page(size) || !is_power_of_2(align)))
+		return ERR_PTR(-EINVAL);
 
 	if (unlikely(!vmap_initialized))
 		return ERR_PTR(-EBUSY);
Signature · 1 line
2.25.1

Makes sense to me.

--
Uladzislau Rezki