* [PATCH] sched/core: switch to BUG_ON()
@ 2017-03-27 7:40 Nicholas Mc Guire
2017-03-27 8:24 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Mc Guire @ 2017-03-27 7:40 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Rusty Russell, Nick Piggin, linux-kernel,
Nicholas Mc Guire
Use BUG_ON() rather than an explicit if followed by BUG().
Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
---
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(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ac88348..b732c16 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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);
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched/core: switch to BUG_ON()
2017-03-27 7:40 [PATCH] sched/core: switch to BUG_ON() Nicholas Mc Guire
@ 2017-03-27 8:24 ` Peter Zijlstra
2017-03-27 9:10 ` Nicholas Mc Guire
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2017-03-27 8:24 UTC (permalink / raw)
To: Nicholas Mc Guire; +Cc: Ingo Molnar, Rusty Russell, Nick Piggin, linux-kernel
On Mon, Mar 27, 2017 at 09:40:46AM +0200, Nicholas Mc Guire wrote:
> 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.
> @@ -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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched/core: switch to BUG_ON()
2017-03-27 8:24 ` Peter Zijlstra
@ 2017-03-27 9:10 ` Nicholas Mc Guire
0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2017-03-27 9:10 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Ingo Molnar, Rusty Russell, Nick Piggin, linux-kernel
On Mon, Mar 27, 2017 at 10:24:40AM +0200, Peter Zijlstra wrote:
> On Mon, Mar 27, 2017 at 09:40:46AM +0200, Nicholas Mc Guire wrote:
>
> > 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.
>
> > @@ -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.
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-27 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-27 7:40 [PATCH] sched/core: switch to BUG_ON() Nicholas Mc Guire
2017-03-27 8:24 ` Peter Zijlstra
2017-03-27 9:10 ` Nicholas Mc Guire
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.