* Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
2017-12-20 5:38 ` [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers Dan Carpenter
@ 2017-12-20 10:30 ` Julia Lawall
2018-01-02 10:26 ` Dan Carpenter
2017-12-20 12:27 ` walter harms
2017-12-20 12:36 ` Julia Lawall
2 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2017-12-20 10:30 UTC (permalink / raw)
To: Dan Carpenter
Cc: Andy Shevchenko, kernel-janitors, Alan Cox, Sakari Ailus,
linux-media, Greg Kroah-Hartman, devel, Kristian Beilke
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?
julia
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
2017-12-20 10:30 ` Julia Lawall
@ 2018-01-02 10:26 ` Dan Carpenter
2018-01-02 10:36 ` Julia Lawall
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2018-01-02 10:26 UTC (permalink / raw)
To: Julia Lawall
Cc: Andy Shevchenko, kernel-janitors, Alan Cox, Sakari Ailus,
linux-media, Greg Kroah-Hartman, devel, Kristian Beilke
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.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
2018-01-02 10:26 ` Dan Carpenter
@ 2018-01-02 10:36 ` Julia Lawall
0 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2018-01-02 10:36 UTC (permalink / raw)
To: Dan Carpenter
Cc: Andy Shevchenko, kernel-janitors, Alan Cox, Sakari Ailus,
linux-media, Greg Kroah-Hartman, devel, Kristian Beilke
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
2017-12-20 5:38 ` [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers Dan Carpenter
2017-12-20 10:30 ` Julia Lawall
@ 2017-12-20 12:27 ` walter harms
2017-12-20 12:36 ` Julia Lawall
2 siblings, 0 replies; 6+ messages in thread
From: walter harms @ 2017-12-20 12:27 UTC (permalink / raw)
To: kernel-janitors
Am 20.12.2017 11:30, schrieb Julia Lawall:
>
>
> 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 guess the idea is to check if a return value gets set and then discarded
because the function returns const.
IMHO this is a case of write-never read like that series what Colin King fixed lately.
re,
wh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers
2017-12-20 5:38 ` [PATCH v1 05/10] staging: atomisp: Remove non-ACPI leftovers Dan Carpenter
2017-12-20 10:30 ` Julia Lawall
2017-12-20 12:27 ` walter harms
@ 2017-12-20 12:36 ` Julia Lawall
2 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2017-12-20 12:36 UTC (permalink / raw)
To: kernel-janitors
On Wed, 20 Dec 2017, walter harms wrote:
>
>
> Am 20.12.2017 11:30, schrieb Julia Lawall:
> >
> >
> > 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 guess the idea is to check if a return value gets set and then discarded
> because the function returns const.
>
> IMHO this is a case of write-never read like that series what Colin King fixed lately.
OK, that makes sense. I guess Colin's patches were in the case where the
right hand side of the assignment is a constant, so non-side effecting.
This case is a bit different. In particular, one might want to skip cases
where the return value is stored but not tested, because the developer
knows that the value is not interesting. But cases where the variable
holding the result of a call is returned as the final result in some cases
but not in the current case could be worth looking at.
At the other end, there are probably a lot of cases of, eg
ty x = get_x(...);
that have been reflexively put at the beginning of functions, because all
other functions have it, but where in the current case x is not used.
julia
>
> re,
> wh
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 6+ messages in thread