Skip to contentSkip to conversation

sched/core: switch to BUG_ON()

PATCH In review Nicholas Mc Guire 2 participants 3 messages Mar 27, 2017 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: switch to BUG_ON()

Use BUG_ON() rather than an explicit if followed by BUG().

---

Found by coccinelle: bugon.cocci
./kernel/sched/core.c:5913:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

There is one checkpatch.pl warning but thats a false positive. To panik() when there is no core to run init on sounds resonable.

Patch was compile-tested with: x86_64_defconfig (implies CONFIG_SMP=y) (some unrelated sparse warnings)

Patch is against 4.11-rc4 (localversion-next is next-20170327)

 kernel/sched/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/core.c +2 -2
index ac88348..b732c16 100644
@@ -5909,8 +5909,8 @@ void __init sched_init_smp(void)
 	mutex_unlock(&sched_domains_mutex);
 
 	/* Move init over to a non-isolated CPU */
-	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
-		BUG();
+	BUG_ON(set_cpus_allowed_ptr(current, non_isolated_cpus) < 0);
+
 	sched_init_granularity();
 	free_cpumask_var(non_isolated_cpus);
 
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 2 lines · Nicholas Mc Guire

Found by coccinelle: bugon.cocci
./kernel/sched/core.c:5913:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

Right, so I disagree with that here.

kernel/sched/core.c void __init sched_init_smp(void) · line 5915

Quoted 10 lines
kernel/sched/core.c +2 -2
@@ -5909,8 +5909,8 @@ void __init sched_init_smp(void)
 	mutex_unlock(&sched_domains_mutex);
 
 	/* Move init over to a non-isolated CPU */
-	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
-		BUG();
+	BUG_ON(set_cpus_allowed_ptr(current, non_isolated_cpus) < 0);
+
 	sched_init_granularity();
 	free_cpumask_var(non_isolated_cpus);

If the condition were without side effects, that pattern would hold, but here the function call set_cpus_allowed_ptr() is very much not a pure function, so wrapping it in a BUG_ON() just fels wrong.

#2 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 2 lines · Nicholas Mc Guire

Found by coccinelle: bugon.cocci
./kernel/sched/core.c:5913:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

Right, so I disagree with that here.

Quoted 3 lines
kernel/sched/core.c +0 -0
@@ -5909,8 +5909,8 @@ void __init sched_init_smp(void)
 	mutex_unlock(&sched_domains_mutex);
 
Quoted 11 lines

kernel/sched/core.c void __init sched_init_smp(void) · line 5915

Quoted 7 lines
kernel/sched/core.c +2 -2
 	/* Move init over to a non-isolated CPU */
-	if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
-		BUG();
+	BUG_ON(set_cpus_allowed_ptr(current, non_isolated_cpus) < 0);
+
 	sched_init_granularity();
 	free_cpumask_var(non_isolated_cpus);

If the condition were without side effects, that pattern would hold, but here the function call set_cpus_allowed_ptr() is very much not a pure function, so wrapping it in a BUG_ON() just fels wrong.

Got it - just looked throug core.c and there it seems only side-effect free test-functions are wrapped in BUG_ON() so this change is inconsistent. Other subsystems seem not to follow that logic - might be worth a note somewhere below Documentation/.

thx!
hofrat