From: Li Chen <me@linux.beauty>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/1] checkpatch: Add warning for msleep with durations suitable for ssleep
Date: Tue, 05 Mar 2024 23:47:32 +0800 [thread overview]
Message-ID: <87edcor88b.wl-me@linux.beauty> (raw)
In-Reply-To: <87frx4r8dt.wl-me@linux.beauty>
From: Li Chen <chenl311@chinatelecom.cn>
This patch enhances checkpatch.pl by introducing a warning for instances
where msleep() is used with durations that are multiples of 1000
milliseconds. Such durations are more semantically appropriate for
ssleep().
The goal is to encourage developers to use the most fitting sleep function,
improving code readability.
Warn when msleep(x000); can be replaced with ssleep(x);
Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
---
scripts/checkpatch.pl | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9c4c4a61bc83..a32df4ead5d4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6599,6 +6599,16 @@ sub process {
}
}
+# warn about msleep() calls with durations that should use ssleep()
+if ($line =~ /\bmsleep\s*\((\d+)\);/) {
+ my $ms_duration = $1;
+ if ($ms_duration >= 1000 && ($ms_duration % 1000) == 0) {
+ my $ss_duration = $ms_duration / 1000;
+ WARN("SSLEEP",
+ "Prefer ssleep($ss_duration) over msleep($ms_duration);\n" . $herecurr);
+ }
+}
+
# check for comparisons of jiffies
if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
WARN("JIFFIES_COMPARISON",
--
2.44.0
next prev parent reply other threads:[~2024-03-05 15:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 15:44 [RFC PATCH 0/1] Guiding Use of ssleep over msleep for Whole-Second Delays Li Chen
2024-03-05 15:47 ` Li Chen [this message]
2024-03-09 19:47 ` [RFC PATCH 1/1] checkpatch: Add warning for msleep with durations suitable for ssleep Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87edcor88b.wl-me@linux.beauty \
--to=me@linux.beauty \
--cc=apw@canonical.com \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox