Re: [PATCH] checkpatch: Flag code that returns a negative number

From: Joe Perches
Date: Fri Jun 03 2016 - 12:16:30 EST


On Fri, 2016-06-03 at 11:07 -0500, Nishanth Menon wrote:
> On 06/03/2016 11:01 AM, Joe Perches wrote:
>
> [...]
> >
> > I did more or less the same grep, and that's somewhat true.
> > -1 though is very common and doesn't need to be replaced.
> OK,
>
> >
> >
> > $ git grep -E "\breturn\s+\-\s*[0-9]+\s*;" * | grep -v "^tools" |
> > grep -vP "return\s*\-1;" | wc -l
> > 211
> >
> > Looking at some of the specific instances of negative return values
> > instead of the line counts though may show otherwise.
> >
> > -EFOO errors aren't always better.
> At least would'nt be a little more readable than obscure -val?
>
> Would we like -[2-9][0-9]* flagged at all even as a check?

I think not, but you should look at the other !-1 instances
and see what you think.

But if it does, it should probably use '-\s*{?!1\b)\d+'

and it should certainly exclude files in tools.