public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	linux-kernel@vger.kernel.org, Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH] driver core: bus: Mark an impossible error path with WARN_ON() in bus_add_driver()
Date: Sun, 15 Sep 2024 16:57:05 +0200	[thread overview]
Message-ID: <2024091510-scarcity-roman-4776@gregkh> (raw)
In-Reply-To: <506644dc-4ca2-4284-a557-eb0ef4bf36bd@icloud.com>

On Sun, Sep 15, 2024 at 10:36:44PM +0800, Zijun Hu wrote:
> On 2024/9/15 21:55, Greg Kroah-Hartman wrote:
> > On Sun, Sep 15, 2024 at 09:38:15PM +0800, Zijun Hu wrote:
> >> On 2024/9/15 21:00, Greg Kroah-Hartman wrote:
> >>> On Sun, Sep 15, 2024 at 06:22:05PM +0800, Zijun Hu wrote:
> >>>> From: Zijun Hu <quic_zijuhu@quicinc.com>
> >>>>
> >>>> driver_attach() called by bus_add_driver() always returns 0, so its
> >>>> corresponding error path will never happen, hence mark the impossible
> >>>> error path with WARN_ON() to remind readers to disregard it.
> >>>
> >>> So you just caused the machine to crash and reboot if that happens
> >>> (remember, panic-on-warn is enabled in a few billion Linux systems...)
> >>>
> >> are there good way to mark a if condition which is always or mostly
> >> evaluated to false currently without any side effect?
> > 
> > If always, then remove the code involved.  If mostly, just do it
> > normally.
> > 
> >> i think this is a generic requirement since readers may not want to
> >> care about things which will never or rarely happen, below link
> >> involves such discussion:
> >> https://lore.kernel.org/all/2024090444-earmark-showpiece-b3dc@gregkh/
> > 
> > Yes, but likely/unlikely is for performance, not for documentation.
> 
> if you git grep unlikely in current kernel tree, you will find
> that there are too many unlikely usages which should be irrelevant
> performance. you maybe look at drivers/base/devres.c.

Yes, and they should be removed, we have someone that normally sweeps
the tree every few years and runs a tool that can compare if those
actually are correct or not, and usually not.

> so i think one of purpose of unlikely may be for the requirement i
> mentioned.

Nope, sorry, performance only.

thanks,

greg k-h

      reply	other threads:[~2024-09-15 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-15 10:22 [PATCH] driver core: bus: Mark an impossible error path with WARN_ON() in bus_add_driver() Zijun Hu
2024-09-15 13:00 ` Greg Kroah-Hartman
2024-09-15 13:38   ` Zijun Hu
2024-09-15 13:55     ` Greg Kroah-Hartman
2024-09-15 14:15       ` Zijun Hu
2024-09-15 14:36       ` Zijun Hu
2024-09-15 14:57         ` Greg Kroah-Hartman [this message]

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=2024091510-scarcity-roman-4776@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_zijuhu@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=zijun_hu@icloud.com \
    /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