Skip to contentSkip to conversation

checkpatch: fix USLEEP_RANGE test

PATCH In review Bruce Allan 2 participants 2 messages Jan 30, 2013 – Jan 31, 2013 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: fix USLEEP_RANGE test

Do not test udelay() for a value less than 10usec when passed a variable instead of a hard-coded number; there is no way for checkpatch to know the value of the variable. As it is today, it will complain about variables with alphanumeric characters plus '_', e.g. foo_bar, but not variables with other characters, eg. foo->bar.

Cc Andy Whitcroft <[email protected]>
---
 scripts/checkpatch.pl |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index 4d2c7df..adfb2f6 100755
@@ -3237,9 +3237,9 @@ sub process {
 		}
 
 # prefer usleep_range over udelay
-		if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
+		if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
 			# ignore udelay's < 10, however
-			if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
+			if (! ($1 < 10) ) {
 				CHK("USLEEP_RANGE",
 				    "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
 			}
maintainer
#1 lore raw
Quoted 2 lines · Bruce Allan

Do not test udelay() for a value less than 10usec when passed a variable instead of a hard-coded number;

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process {

Quoted 1 line
scripts/checkpatch.pl +0 -0
@@ -3237,9 +3237,9 @@ sub process {

[]

scripts/checkpatch.pl sub process { · line 3245

Quoted 9 lines
scripts/checkpatch.pl +2 -2
 # prefer usleep_range over udelay
-		if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
+		if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
 			# ignore udelay's < 10, however
-			if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
+			if (! ($1 < 10) ) {
 				CHK("USLEEP_RANGE",
 				    "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
 			}

Thanks Bruce.

Just a trivial comment:

Maybe this would be a little neater as

		if ($line =~ \budelay\s*\(\s*(\d+)\s*\) &&
		    $1 >= 10) {
			CHK(etc...)
		}

No worries though.