checkpatch: Do not complain about positive return values starting with EPOLL
PATCH 1/1 checkpatch: Do not complain about positive return values starting with EPOLL
checkpatch complains about positive return values of poll functions. Example:
WARNING: return of an errno should typically be negative (ie: return -EPOLLIN)
+ return EPOLLIN;
Poll functions return positive values. The defines for the return values of poll functions all start with EPOLL, resulting in a number of false positives. An often used workaround is to assign poll function return values to variables and returning that variable, but that is a less than perfect solution.
There is no error definition which starts with EPOLL, so it is safe to omit the warning for return values starting with EPOLL.
--- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
@@ -5458,7 +5458,8 @@ sub process { # Return of what appears to be an errno should normally be negative if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { my $name = $1; - if ($name ne 'EOF' && $name ne 'ERROR') { + if ($name ne 'EOF' && $name ne 'ERROR' && + rindex($name, 'EPOLL', 0) != 0) { WARN("USE_NEGATIVE_ERRNO", "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); }
Signature · 1 line
2.25.1
Joe Perches
maintainerQuoted 6 lines · Guenter Roeck
checkpatch complains about positive return values of poll functions. Example:
WARNING: return of an errno should typically be negative (ie: return
-EPOLLIN)(quoted diff) +1
-0+ return EPOLLIN;
Quoted 8 lines
Poll functions return positive values. The defines for the return values of poll functions all start with EPOLL, resulting in a number of false positives. An often used workaround is to assign poll function return values to variables and returning that variable, but that is a less than perfect solution.
There is no error definition which starts with EPOLL, so it is safe to omit the warning for return values starting with EPOLL.
Seems OK but
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub process { · line 5462
Quoted 7 lines
scripts/checkpatch.pl +2
-1@@ -5458,7 +5458,8 @@ sub process { # Return of what appears to be an errno should normally be negative if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { my $name = $1; - if ($name ne 'EOF' && $name ne 'ERROR') { + if ($name ne 'EOF' && $name ne 'ERROR' && + rindex($name, 'EPOLL', 0) != 0) {
rindex is a bit harder to read so my preference would be for the simpler:
if ($name ne 'EOF' && $name ne 'ERROR' && $name !~ /^EPOLL/) {Quoted 3 lines
scripts/checkpatch.pl +0
-0WARN("USE_NEGATIVE_ERRNO", "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); }