Messages in this thread Patch in this message | | | Subject | [PATCH] checkpatch: Warn on logging functions with KERN_<LEVEL> | From | Joe Perches <> | Date | Wed, 01 Oct 2014 21:08:20 -0700 |
| |
Warn on probable misuses of logging functions with KERN_<LEVEL> like pr_err(KERN_ERR "foo\n");
Suggested-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Joe Perches <joe@perches.com>
--- > > - 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;
| |