public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
Date: Wed, 17 Mar 2021 21:05:29 +0100	[thread overview]
Message-ID: <20210317200529.GB3830960@gmail.com> (raw)
In-Reply-To: <CAK8P3a2qqWV3RGvb4ooiz4LS5GAKL0OHEiVtdgnHAgtmiRDSNA@mail.gmail.com>


* Arnd Bergmann <arnd@kernel.org> wrote:

> On Wed, Mar 17, 2021 at 9:45 AM Ingo Molnar <mingo@kernel.org> wrote:
> > * Ingo Molnar <mingo@kernel.org> wrote:
> > > * Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
> > >
> > > > Fix the following coccicheck warnings:
> > > >
> > > > ./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
> > > > condition followed by BUG.
> > > >
> > > > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > > > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > > > ---
> > > >  kernel/sched/core.c | 3 +--
> > > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > > >
> > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > > index 9819121..7392bc0 100644
> > > > --- a/kernel/sched/core.c
> > > > +++ b/kernel/sched/core.c
> > > > @@ -8035,8 +8035,7 @@ 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, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
> > > > -           BUG();
> > > > +   BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
> > >
> > > The patch doesn't quite do what the title & changelog claims...
> >
> > More importantly, we use this pattern when we don't want !CONFIG_BUG
> > to remove the 'condition'.
> >
> > I.e. the "side effect" here is important scheduler logic. It must
> > never be optimized out.
> 
> This behavior for !CONFIG_BUG has changed a while ago, it is now safe
> to rely on the side-effect of the BUG_ON() condition regardless of
> CONFIG_BUG. When that option is disabled, running into the condition
> just ends up in a "do {} while (1)" loop.

Dunno, I still think it's not a particularly clean pattern to 'hide' 
significant side effects within a BUG_ON().

Thanks,

	Ingo

  reply	other threads:[~2021-03-17 20:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17  2:45 [PATCH] sched: replace if (cond) BUG() with BUG_ON() Jiapeng Chong
2021-03-17  8:39 ` Ingo Molnar
2021-03-17  8:41   ` Ingo Molnar
2021-03-17 12:55     ` Arnd Bergmann
2021-03-17 20:05       ` Ingo Molnar [this message]
2021-03-17 21:38         ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2021-03-17  6:45 Jiapeng Chong
2021-03-17  7:00 ` Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210317200529.GB3830960@gmail.com \
    --to=mingo@kernel.org \
    --cc=arnd@kernel.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox