Re: [PATCH] usb: ohci: remove unreachable platform_driver_unregister() call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
> > 
> > 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.

regards,
dan carpenter




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux