Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls

From: Joe Perches

Date: Sun Feb 08 2026 - 11:36:25 EST


On Sun, 2026-02-08 at 10:59 -0500, Neel Bullywon wrote:
> Update the MSLEEP warning to suggest fsleep() as a duration based
> sleep API. fsleep() autoselects the best sleep mechanism (udelay,
> usleep_range, or msleep) based on the requested duration, making
> it the preferred replacement for short msleep() calls.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -6636,7 +6636,7 @@ sub process {
> if ($line =~ /\bmsleep\s*\((\d+)\);/) {
> if ($1 < 20) {
> WARN("MSLEEP",
> - "msleep < 20ms can sleep for up to 20ms; see function description of msleep().\n" . $herecurr);
> + "msleep < 20ms can sleep for up to 20ms; see function description of fsleep().\n" . $herecurr);
> }
> }

maybe change msleep to a #define macro so if the argument is
constant call fsleep instead

Something like:

#define msleep(msecs) \
do { \
if (__builtin_constant_p(msecs) && (msecs) < 20) \
fsleep((msecs) * 1000UL); \
else \
msleep(msecs); \
} while (0)

and change the definition of void msleep(unsigned int msecs) to

void (msleep)(unsigned int msecs)
{
etc...
}

and remove the checkpatch test.