Skip to contentSkip to conversation

sysctl: Use BUG_ON instead of BUG

PATCH In review Prasad Joshi 2 participants 2 messages Sep 3, 2012 – Sep 4, 2012

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

PATCH 1/1 sysctl: Use BUG_ON instead of BUG

The use of if (!head) BUG(); can be replaced with single line BUG_ON(!head).

---
 fs/proc/proc_sysctl.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/proc/proc_sysctl.c +1 -2
index dfafeb2..63bdfa0 100644
@@ -266,8 +266,7 @@ void sysctl_head_put(struct ctl_table_header *head)
 
 static struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
 {
-	if (!head)
-		BUG();
+	BUG_ON(!head);
 	spin_lock(&sysctl_lock);
 	if (!use_table(head))
 		head = ERR_PTR(-ENOENT);
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 13 lines · On Mon, 3 Sep 2012 09:00:25 +0530 Prasad Joshi <[email protected]>…

The use of if (!head) BUG(); can be replaced with single line BUG_ON(!head).

---
 fs/proc/proc_sysctl.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/proc/proc_sysctl.c +0 -0
index dfafeb2..63bdfa0 100644

fs/proc/proc_sysctl.c void sysctl_head_put(struct ctl_table_header *head) · line 272

Quoted 9 lines
fs/proc/proc_sysctl.c +1 -2
@@ -266,8 +266,7 @@ void sysctl_head_put(struct ctl_table_header *head)
 
 static struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
 {
-	if (!head)
-		BUG();
+	BUG_ON(!head);
 	spin_lock(&sysctl_lock);
 	if (!use_table(head))
 		head = ERR_PTR(-ENOENT);

We could just remove the check altogether. The resulting NULL pointer deref oops in use_table() will give us the same info as that BUG().