Skip to content

Commit

Permalink
checkpatch: warn on uses of __constant_<foo> functions
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Andy Whitcroft <[email protected]>
Cc: Simon Wunderlich <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Apr 3, 2014
1 parent 2435880 commit fbdb813
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3931,6 +3931,19 @@ sub process {
}
}

# don't use __constant_<foo> functions outside of include/uapi/
if ($realfile !~ m@^include/uapi/@ &&
$line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
my $constant_func = $1;
my $func = $constant_func;
$func =~ s/^__constant_//;
if (WARN("CONSTANT_CONVERSION",
"$constant_func should be $func\n" . $herecurr) &&
$fix) {
$fixed[$linenr - 1] =~ s/\b$constant_func\b/$func/g;
}
}

# prefer usleep_range over udelay
if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
my $delay = $1;
Expand Down

0 comments on commit fbdb813

Please sign in to comment.