Skip to contentSkip to conversation

checkpatch: Add warnings for use of mdelay()

PATCH In review Israel Schlesinger 2 participants 2 messages Jul 27, 2010 – Jul 28, 2010 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: Add warnings for use of mdelay()

mdelay is a busy-wait loop which is wasteful. If at all possible, callers should use msleep instead of mdelay.

The only time mdelay is really appropriate is in atomic context, however, delays of 1ms+ in atomic context are rather expensive, so a warning for this case is probably appropriate as well to encourage people to move such expensive delays outside of atomic context

---
 scripts/checkpatch.pl |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +5 -0
index bd88f11..9ce1cb5 100755
@@ -2570,6 +2570,11 @@ sub process {
 			}
 		}
 
+# check the patch for use of mdelay
+		if ($line =~ /\bmdelay\s*\(/) {
+			WARN("use of mdelay() found: msleep() is the preferred API.\n" . $line );
+		}
+
 # warn about #ifdefs in C files
 #		if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
 #			print "#ifdef in C files should be avoided\n";
Signature · 5 lines
1.7.0.2

-- 
Employee of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
#1 lore raw
Quoted 8 lines · Israel Schlesinger

mdelay is a busy-wait loop which is wasteful. If at all possible, callers should use msleep instead of mdelay.

The only time mdelay is really appropriate is in atomic context, however, delays of 1ms+ in atomic context are rather expensive, so a warning for this case is probably appropriate as well to encourage people to move such expensive delays outside of atomic context

Then udelay() is also preferred...