From: Alan Stern <stern@rowland.harvard.edu>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jay Fang <f.fangjian@huawei.com>,
linux-usb@vger.kernel.org, tangzihao1@hisilicon.com,
huangdaode@huawei.com
Subject: Re: [PATCH] usb: ohci: remove unreachable platform_driver_unregister() call
Date: Mon, 22 Mar 2021 12:44:09 -0400 [thread overview]
Message-ID: <20210322164409.GC667925@rowland.harvard.edu> (raw)
In-Reply-To: <20210322045850.GA1667@kadam>
On Mon, Mar 22, 2021 at 07:58:50AM +0300, Dan Carpenter wrote:
> On Fri, Mar 19, 2021 at 10:24:43PM -0400, Alan Stern wrote:
> > On Sat, Mar 20, 2021 at 09:31:51AM +0800, Jay Fang wrote:
> > > From: Zihao Tang <tangzihao1@hisilicon.com>
> > >
> > > Fix the following smatch warnings:
> > >
> > > drivers/usb/host/ohci-hcd.c:1318 ohci_hcd_mod_init() warn:
> > > ignoring unreachable code.
> > >
> > > platform_driver_register(&TMIO_OHCI_DRIVER) is the last
> > > platform_driver_register() call in ohci_hcd_mod_init(), so if it
> > > failed, there's no need to unregister it, but just goto error_tmio.
> > >
> > > So remove the unreachable platform_driver_unregister(&TMIO_OHCI_DRIVER).
> > > No functionality change.
> >
> > Doesn't the compiler realize that the call is unreachable, and
> > therefore avoid generating any object for it?
> >
>
> This is a static checker warning. For example, Heart Bleed bug was an
> ignored unreachable code static checker warning.
>
> > It's true that the function call is, strictly speaking, unnecessary.
> > However, it provides a pleasing symmetry and it acts as a guide in the
> > unlikely event that anyone wants to add another platform-specific
> > driver in the future.
>
> Hopefully future programmers can figure out basic stuff like that.
>
> This code doesn't trigger a Smatch warning on my .config because the
> Smatch check doesn't warn if the previous line was an #endif. On the
> other hand, the ifdefs are also why I forwarded the email when I saw the
> warning from kbuild. Normally kbuild is better at picking the person
> to blame but because this is a .config thing that confused it. Anyway,
> I glanced at the warning and thought it looked suspicious enough to
> warrant a further look.
>
> When I first wrote the Smatch unreachable code warning there were a
> handful of places which used that style of code:
>
> return 0;
>
> unreachable_release();
> err_release:
> release_something();
>
> I just left those as-is because it was obvious to me that it was done
> intentionally. However, it seems that other people have removed all of
> those behind my back so I can't find an example of this now except for
> in ohci_hcd_mod_init().
>
> Anyway, I would have put a special case to silence these false positives
> but it wasn't common practice in 2014 and no one does it these days.
Well, I guess it would be okay to convert the code to a comment. Just
so long as it isn't removed entirely.
Alan Stern
prev parent reply other threads:[~2021-03-22 16:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-20 1:31 [PATCH] usb: ohci: remove unreachable platform_driver_unregister() call Jay Fang
2021-03-20 2:24 ` Alan Stern
2021-03-22 4:58 ` Dan Carpenter
2021-03-22 16:44 ` Alan Stern [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=20210322164409.GC667925@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=dan.carpenter@oracle.com \
--cc=f.fangjian@huawei.com \
--cc=huangdaode@huawei.com \
--cc=linux-usb@vger.kernel.org \
--cc=tangzihao1@hisilicon.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;
as well as URLs for NNTP newsgroup(s).