All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	kernel-janitors@vger.kernel.org, Alan Cox <alan@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, Kristian Beilke <beilke@posteo.de>
Subject: Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
Date: Tue, 2 Jan 2018 11:36:05 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1801021135000.24055@hadrien> (raw)
In-Reply-To: <20180102102644.km2lb65ehesphso7@mwanda>



On Tue, 2 Jan 2018, Dan Carpenter wrote:

> On Wed, Dec 20, 2017 at 11:30:01AM +0100, Julia Lawall wrote:
> >
> >
> > On Wed, 20 Dec 2017, Dan Carpenter wrote:
> >
> > > On Tue, Dec 19, 2017 at 10:59:52PM +0200, Andy Shevchenko wrote:
> > > > @@ -914,9 +904,7 @@ static int lm3554_probe(struct i2c_client *client)
> > > >  		dev_err(&client->dev, "gpio request/direction_output fail");
> > > >  		goto fail2;
> > > >  	}
> > > > -	if (ACPI_HANDLE(&client->dev))
> > > > -		err = atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
> > > > -	return 0;
> > > > +	return atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
> > > >  fail2:
> > > >  	media_entity_cleanup(&flash->sd.entity);
> > > >  	v4l2_ctrl_handler_free(&flash->ctrl_handler);
> > >
> > > Actually every place where we directly return a function call is wrong
> > > and needs error handling added.  I've been meaning to write a Smatch
> > > check for this because it's a common anti-pattern we don't check the
> > > last function call for errors.
> > >
> > > Someone could probably do the same in Coccinelle if they want.
> >
> > I'm not sure what you are suggesting.  Is every case of return f(...);
> > for any f wrong?  Or is it a particular function that is of concern?  Or
> > would it be that every function call that has error handling somewhere
> > should have error handling everywhere?  Or is it related to what seems to
> > be the problem in the above code that err is initialized but nothing
> > happens to it?
> >
>
> I was just thinking that it's a common pattern to treat the last
> function call differently and one mistake I often see looks like this:
>
> 	ret = frob();
> 	if (ret) {
> 		cleanup();
> 		return ret;
> 	}
>
> 	return another_function();
>
> No error handling for the last function call.

OK, I see.  When there was error handling code along the way, a direct
return of a function that could fail needs error handling code too.

Thanks for the clarification,

julia

WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia.lawall@lip6.fr>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	kernel-janitors@vger.kernel.org, Alan Cox <alan@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, Kristian Beilke <beilke@posteo.de>
Subject: Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
Date: Tue, 02 Jan 2018 10:36:05 +0000	[thread overview]
Message-ID: <alpine.DEB.2.20.1801021135000.24055@hadrien> (raw)
In-Reply-To: <20180102102644.km2lb65ehesphso7@mwanda>



On Tue, 2 Jan 2018, Dan Carpenter wrote:

> On Wed, Dec 20, 2017 at 11:30:01AM +0100, Julia Lawall wrote:
> >
> >
> > On Wed, 20 Dec 2017, Dan Carpenter wrote:
> >
> > > On Tue, Dec 19, 2017 at 10:59:52PM +0200, Andy Shevchenko wrote:
> > > > @@ -914,9 +904,7 @@ static int lm3554_probe(struct i2c_client *client)
> > > >  		dev_err(&client->dev, "gpio request/direction_output fail");
> > > >  		goto fail2;
> > > >  	}
> > > > -	if (ACPI_HANDLE(&client->dev))
> > > > -		err = atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
> > > > -	return 0;
> > > > +	return atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
> > > >  fail2:
> > > >  	media_entity_cleanup(&flash->sd.entity);
> > > >  	v4l2_ctrl_handler_free(&flash->ctrl_handler);
> > >
> > > Actually every place where we directly return a function call is wrong
> > > and needs error handling added.  I've been meaning to write a Smatch
> > > check for this because it's a common anti-pattern we don't check the
> > > last function call for errors.
> > >
> > > Someone could probably do the same in Coccinelle if they want.
> >
> > I'm not sure what you are suggesting.  Is every case of return f(...);
> > for any f wrong?  Or is it a particular function that is of concern?  Or
> > would it be that every function call that has error handling somewhere
> > should have error handling everywhere?  Or is it related to what seems to
> > be the problem in the above code that err is initialized but nothing
> > happens to it?
> >
>
> I was just thinking that it's a common pattern to treat the last
> function call differently and one mistake I often see looks like this:
>
> 	ret = frob();
> 	if (ret) {
> 		cleanup();
> 		return ret;
> 	}
>
> 	return another_function();
>
> No error handling for the last function call.

OK, I see.  When there was error handling code along the way, a direct
return of a function that could fail needs error handling code too.

Thanks for the clarification,

julia

  reply	other threads:[~2018-01-02 10:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-19 20:59 [PATCH v1 01/10] staging: atomisp: Don't leak GPIO resources if clk_get() failed Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 02/10] staging: atomisp: Remove duplicate NULL-check Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 03/10] staging: atomisp: lm3554: Fix control values Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 04/10] staging: atomisp: Disable custom format for now Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers Andy Shevchenko
2017-12-20  4:54   ` Dan Carpenter
2017-12-20 10:24     ` Andy Shevchenko
2017-12-21 22:34       ` Sakari Ailus
2017-12-20  5:38   ` Dan Carpenter
2017-12-20  5:38     ` Dan Carpenter
2017-12-20 10:30     ` Julia Lawall
2017-12-20 10:30       ` Julia Lawall
2018-01-02 10:26       ` Dan Carpenter
2018-01-02 10:26         ` Dan Carpenter
2018-01-02 10:36         ` Julia Lawall [this message]
2018-01-02 10:36           ` Julia Lawall
2017-12-20 12:27     ` walter harms
2017-12-20 12:36     ` Julia Lawall
2017-12-19 20:59 ` [PATCH v1 06/10] staging: atomisp: Switch to use struct device_driver directly Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 07/10] staging: atomisp: Remove redundant PCI code Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 08/10] staging: atomisp: Unexport local function Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 09/10] staging: atomisp: Use standard DMI match table Andy Shevchenko
2017-12-19 20:59 ` [PATCH v1 10/10] staging: atomisp: Fix DMI matching entry for MRD7 Andy Shevchenko

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=alpine.DEB.2.20.1801021135000.24055@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=alan@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=beilke@posteo.de \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.