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]
Date: Tue, 05 Mar 2024 23:47:32 +0800
From: Li Chen <me@...ux.beauty>
To: Andy Whitcroft <apw@...onical.com>,
	Joe Perches <joe@...ches.com>,
	Dwaipayan Ray <dwaipayanray1@...il.com>,
	Lukas Bulwahn <lukas.bulwahn@...il.com>,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH 1/1] checkpatch: Add warning for msleep with durations suitable for ssleep

From: Li Chen <chenl311@...natelecom.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@...natelecom.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ