Re: checkpatch.pl warning for "return" with value

From: Joe Perches
Date: Fri Apr 17 2020 - 14:57:58 EST


On Fri, 2020-04-17 at 14:52 -0400, Luben Tuikov wrote:
> On 2020-04-17 1:32 p.m., Joe Perches wrote:
[]
> > if (<atypical_condition>) {
> > ...;
> > return <atypical_result>;
> > }
> >
> > ...;
> > return <typical_result>;
> > }
> >
> > If you want to code it, and it works, go ahead, but I
> > won't attempt it because I think it's not appropriate.
>
> For error checking, when the 2nd ellipsis is
> a long, long body of the function, so that the error
> checking is done at the top, then long body,
> then at the bottom we return some computed value.
> But in the case I have above, it's a compact if-else
> at the bottom of the function.

which could not be differentiated from a function like

{
...;
err = func(...);
if (err) {
report("err: %d\n", err);
return err;
}

...;
return 0;

> In the example I gave above, there is no "typical" or
> "atypical" condition--it's just checking a condition
> and deciding what to do, all at the bottom of
> a function. (And that condition, samples
> an external stimuli, which cannot be predicted.)
[]
> Since we're returning a different result and since
> it works fine with a triplet, could you fix the binary
> case above to not complain?

No.