lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a4cb5e297e05627494dbb6737ef80bb3fd7c03bd.camel@perches.com>
Date: Sun, 08 Feb 2026 10:44:30 -0800
From: Joe Perches <joe@...ches.com>
To: Neel Bullywon <neelb2403@...il.com>, apw@...onical.com
Cc: dwaipayanray1@...il.com, lukas.bulwahn@...il.com, 
	andriy.shevchenko@...el.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] checkpatch: suggest fsleep() for short msleep() calls

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ