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

From: Joe Perches

Date: Sun Feb 08 2026 - 13:44:47 EST


On Sun, 2026-02-08 at 08:36 -0800, Joe Perches wrote:
> 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.

And there are quite a lot of msleep(<20)

$ git grep -Pon '\bmsleep\s*\(\s*(?:\d+)\s*\)' | \
awk -F'(' '{ if (strtonum($2) < 20) print; }' | \
wc -l
1709