Re: [PATCH] checkpatch: Warn on unnecessary void function return statements

Joe Perches
2014-06-17T00:28:23Z

On Mon, 2014-06-16 at 16:28 -0700, Anish Bhatt wrote:
> This seems to ignore the ability to exit from void
> return functions via a `return;` in case of an error
> or similar. Any attempt to bail out generates warnings
> with checkpathch.pl Perhaps it should check for returns
> only at the end of the function ? If not, is there a
> suggested way to do this ? goto labels can't be directly
> used in place either

The only time checkpatch should bleat any message
is when there is a return; statement indented with
a single tab.

This form should be fine and not generate any
checkpatch warning.

void function(void)
{
...

if (err)
return;

...

}

If you want to use exit labels, I suggest you
use this form:

void function(void)
{

...

if (err)
goto exit;

...

exit:
;
}