linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: check for missing \n at the end of logging message
@ 2020-04-07 20:49 Christophe JAILLET
  2020-04-08  0:33 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Christophe JAILLET @ 2020-04-07 20:49 UTC (permalink / raw)
  To: apw, joe; +Cc: linux-kernel, kernel-janitors, Christophe JAILLET

Strings logged with pr_xxx and dev_xxx often lack a trailing '\n'.
Introduce new tests to try to catch them early.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This is more a PoC for now.

Regex could be improved, merged, ...
We could also check for surrounding pr_cont...

This patch is based on idea from [1]. coccinelle spots too many places
where \n are missing (~ 2800 with the heuristic I've used).
Fixing them would be painful.
I instead propose to teach checkpatch.pl about it to try to spot cases
early and avoid introducing new cases.

[1]: https://marc.info/?l=kernel-janitors&m=158619533629657&w=4
---
 scripts/checkpatch.pl | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c392ab8ea12e..792804bd6ad9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5676,6 +5676,16 @@ sub process {
 			}
 		}
 
+# check for missing \n at the end of logging function
+		if ($line =~ /\bpr_(emerg|alert|crit|err|warning|warn|notice|info|debug|dbg)\s*\("([^"]*(?<!\\n))"/) {
+			WARN("MISSING NL",
+			     "Possible missing '\\n' at the end of a log message\n" . $hereprev);
+		}
+		if ($line =~ /\bdev_(emerg|alert|crit|err|warning|warn|notice|info|debug|dbg)\s*\([^,]*,\s*"([^"]*(?<!\\n))"/) {
+			WARN("MISSING NL",
+			     "Possible missing '\\n' at the end of a log message\n" . $hereprev);
+		}
+
 # check for logging functions with KERN_<LEVEL>
 		if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
 		    $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2020-04-11 10:27 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 20:49 [PATCH] checkpatch: check for missing \n at the end of logging message Christophe JAILLET
2020-04-08  0:33 ` Joe Perches
2020-04-08 20:19   ` Marion & Christophe JAILLET
2020-04-08  2:14 ` Joe Perches
2020-04-08 20:23   ` Marion & Christophe JAILLET
2020-04-09  3:10     ` Joe Perches
2020-04-09  7:24       ` Christophe JAILLET
2020-04-09  7:24         ` Christophe JAILLET
2020-04-09 15:29         ` Joe Perches
2020-04-09 17:34           ` Christophe JAILLET
2020-04-09 17:34             ` Christophe JAILLET
2020-04-09 17:50             ` Joe Perches
2020-04-09 18:52               ` Christophe JAILLET
2020-04-09 18:52                 ` Christophe JAILLET
2020-04-09 21:40                 ` Joe Perches
2020-04-09 10:40       ` Dan Carpenter
2020-04-10 17:35   ` Christophe JAILLET
2020-04-10 19:46     ` Joe Perches
2020-04-10 19:53       ` Joe Perches
2020-04-11  6:48         ` Christophe JAILLET
2020-04-11  6:48           ` Christophe JAILLET
2020-04-11 10:10           ` Andy? checkpatch $stat question (was: Re: [PATCH] checkpatch: check for missing \n at the end of logging message) Joe Perches
2020-04-11  7:12         ` [PATCH] checkpatch: check for missing \n at the end of logging message Christophe JAILLET
2020-04-11  7:12           ` Christophe JAILLET
2020-04-11  7:13           ` Marion & Christophe JAILLET
2020-04-11 10:17           ` Joe Perches
2020-04-11 10:27             ` Christophe JAILLET
2020-04-11 10:27               ` Christophe JAILLET
2020-04-10 19:34 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).