Commit 53a3c4487a05b8f26ef72fe434a750a3402c998f

Authored by Andy Whitcroft
Committed by Linus Torvalds
1 parent 9446ef569c

checkpatch: returning errno typically should be negative

Add a (strict mode only) test to check for non-negative returns of what
appear to be errno values as the majority case these should indeed be
negative.

Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 7 additions and 0 deletions Side-by-side Diff

scripts/checkpatch.pl
... ... @@ -2204,6 +2204,13 @@
2204 2204 ERROR("space required before the open parenthesis '('\n" . $herecurr);
2205 2205 }
2206 2206 }
  2207 +# Return of what appears to be an errno should normally be -'ve
  2208 + if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
  2209 + my $name = $1;
  2210 + if ($name ne 'EOF' && $name ne 'ERROR') {
  2211 + WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
  2212 + }
  2213 + }
2207 2214  
2208 2215 # Need a space before open parenthesis after if, while etc
2209 2216 if ($line=~/\b(if|while|for|switch)\(/) {