[PATCH] checkpatch: Warn on logging functions with KERN_<LEVEL>

From: Joe Perches
Date: Thu Oct 02 2014 - 00:08:28 EST


Warn on probable misuses of logging functions with KERN_<LEVEL>
like pr_err(KERN_ERR "foo\n");

Suggested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>

---
> > - printk(KERN_ERR "ksm: register sysfs failed\n");
> > + pr_err(KERN_ERR "ksm: register sysfs failed\n");

> A quick grep indicates that we have the same mistake in tens of places.
> checkpatch rule, please?

scripts/checkpatch.pl | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 52a223e..374abf4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4447,6 +4447,17 @@ sub process {
}
}

+# check for logging functions with KERN_<LEVEL>
+ if ($line !~ /printk\s*\(/ &&
+ $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
+ my $level = $1;
+ if (WARN("UNNECESSARY_KERN_LEVEL",
+ "Possible unnecessary $level\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\s*$level\s*//;
+ }
+ }
+
# check for bad placement of section $InitAttribute (e.g.: __initdata)
if ($line =~ /(\b$InitAttribute\b)/) {
my $attr = $1;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/