Skip to content

Commit fbdb813

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: warn on uses of __constant_<foo> functions
Emit a warning when using any of these __constant_<foo> forms: __constant_cpu_to_be[x] __constant_cpu_to_le[x] __constant_be[x]_to_cpu __constant_le[x]_to_cpu __constant_htons __constant_ntohs Using any of these outside of include/uapi/ isn't preferred as using the function without __constant_ is identical when the argument is a constant. Signed-off-by: Joe Perches <joe@perches.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Simon Wunderlich <sw@simonwunderlich.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2435880 commit fbdb813

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,6 +3931,19 @@ sub process {
39313931
}
39323932
}
39333933

3934+
# don't use __constant_<foo> functions outside of include/uapi/
3935+
if ($realfile !~ m@^include/uapi/@ &&
3936+
$line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
3937+
my $constant_func = $1;
3938+
my $func = $constant_func;
3939+
$func =~ s/^__constant_//;
3940+
if (WARN("CONSTANT_CONVERSION",
3941+
"$constant_func should be $func\n" . $herecurr) &&
3942+
$fix) {
3943+
$fixed[$linenr - 1] =~ s/\b$constant_func\b/$func/g;
3944+
}
3945+
}
3946+
39343947
# prefer usleep_range over udelay
39353948
if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
39363949
my $delay = $1;

0 commit comments

Comments
 (0)