public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Nihar Chaithanya <niharchaithanya@gmail.com>
Cc: dpenkler@gmail.com, dan.carpenter@linaro.org,
	roheetchavan@gmail.com, arnd@arndb.de,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org
Subject: Re: [PATCH v2] staging: gpib: cb7210: Add error handling
Date: Sat, 21 Dec 2024 14:27:11 +0100	[thread overview]
Message-ID: <2024122150-overarch-cough-a86b@gregkh> (raw)
In-Reply-To: <fc10d4ac-8ad0-4756-8d65-8700aa7f8f21@gmail.com>

On Sat, Dec 21, 2024 at 04:59:31PM +0530, Nihar Chaithanya wrote:
> 
> On 21/12/24 15:13, Greg KH wrote:
> > On Sat, Dec 21, 2024 at 10:25:41AM +0100, Greg KH wrote:
> > > On Sat, Dec 21, 2024 at 02:41:25PM +0530, Nihar Chaithanya wrote:
> > > > The if condition in cb7210_init_module() would always fail as
> > > > the value of err is constantly 0. The function
> > > > cb_pcmcia_init_module() can be refactored into a single line,
> > > > and can be replaced entirely with pcmcia_register_driver().
> > > > 
> > > > Replace redundant cb_pcmcia_init_module() with
> > > > pcmcia_register_driver() which returns appropriate error code if
> > > > it fails. Handle the error if it fails and print the debug message.
> > > > 
> > > > This issue was reported by Coverity Scan.
> > > > Report:
> > > > CID 1635894: (#1 of 1): 'Constant' variable guards dead code (DEADCODE)
> > > > dead_error_line: Execution cannot reach this statement: return -1;.
> > > > 
> > > > Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
> > > > ---
> > > > v1 --> v2: Replaced the redundant cb_pcmcia_init_module() with
> > > > 	   pcmcia_register_driver().
> > > > 
> > > >   drivers/staging/gpib/cb7210/cb7210.c | 13 ++++---------
> > > >   1 file changed, 4 insertions(+), 9 deletions(-)
> > > > 
> > > > diff --git a/drivers/staging/gpib/cb7210/cb7210.c b/drivers/staging/gpib/cb7210/cb7210.c
> > > > index 63df7f3eb3f3..abd6632d8448 100644
> > > > --- a/drivers/staging/gpib/cb7210/cb7210.c
> > > > +++ b/drivers/staging/gpib/cb7210/cb7210.c
> > > > @@ -1351,12 +1351,6 @@ static struct pcmcia_driver cb_gpib_cs_driver = {
> > > >   	.resume		= cb_gpib_resume,
> > > >   };
> > > > -int cb_pcmcia_init_module(void)
> > > > -{
> > > > -	pcmcia_register_driver(&cb_gpib_cs_driver);
> > > > -	return 0;
> > > > -}
> > > > -
> > > >   void cb_pcmcia_cleanup_module(void)
> > > >   {
> > > >   	DEBUG(0, "cb_gpib_cs: unloading\n");
> > > > @@ -1526,11 +1520,12 @@ static int __init cb7210_init_module(void)
> > > >   	gpib_register_driver(&cb_pcmcia_interface, THIS_MODULE);
> > > >   	gpib_register_driver(&cb_pcmcia_accel_interface, THIS_MODULE);
> > > >   	gpib_register_driver(&cb_pcmcia_unaccel_interface, THIS_MODULE);
> > > > -	err += cb_pcmcia_init_module();
> > > > +	err = pcmcia_register_driver(&cb_gpib_cs_driver);
> > > >   #endif
> > > > -	if (err)
> > > > +	if (err) {
> > > > +		pr_err("cb7210: registering PCMCIA driver with the bus core failed\n");
> > > >   		return -1;
> > > Not your issue, but "-1" is not a valid error number, shouldn't this be
> > > returning a real error (i.e. the one that was returned?)
> > > 
> > > And err += is crazy, thanks for removing that, BUT you forgot to unwind
> > > the previous functions so now if pcmcia_register_driver() fails, you
> > > have a semi-registered system and then the module will unload (as init
> > > fails) and bad things will happen :(
> So I need be unregistering the driver if the pcmcia_register_driver() fails
> right?

Yes, all of them.

thanks,

greg k-h

      reply	other threads:[~2024-12-21 13:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-21  9:11 [PATCH v2] staging: gpib: cb7210: Add error handling Nihar Chaithanya
2024-12-21  9:25 ` Greg KH
2024-12-21  9:43   ` Greg KH
2024-12-21 11:29     ` Nihar Chaithanya
2024-12-21 13:27       ` Greg KH [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=2024122150-overarch-cough-a86b@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=dan.carpenter@linaro.org \
    --cc=dpenkler@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=niharchaithanya@gmail.com \
    --cc=roheetchavan@gmail.com \
    --cc=skhan@linuxfoundation.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