checkpatch: add new warning when lookup_symbol_name() is used
PATCH 1/1 checkpatch: add new warning when lookup_symbol_name() is used
In most cases people use lookup_symbol_name() to resolve a kernel symbol and then print it via printk().
In such cases using the %ps, %pS, %pSR or %pB printk formats are easier to use and thus should be preferred.
scripts/checkpatch.pl +6 -0
@@ -4317,6 +4317,12 @@ sub process { "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } +# avoid lookup_symbol_name() + if ($line =~ /\blookup_symbol_name\b/) { + WARN("PREFER_PRINTK_FORMAT", + "If possible prefer %ps or %pS printk format string to print symbol name instead of using lookup_symbol_name()\n" . $herecurr); + } + # check for uses of printk_ratelimit if ($line =~ /\bprintk_ratelimit\s*\(/) { WARN("PRINTK_RATELIMITED",
Joe Perches
maintainerQuoted 5 lines · Helge Deller
In most cases people use
lookup_symbol_name()to resolve a kernel symbol and then print it viaprintk().In such cases using the %ps, %pS, %pSR or %pB printk formats are easier to use and thus should be preferred.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub process { · line 4328
Quoted 13 lines
scripts/checkpatch.pl +6
-0@@ -4317,6 +4317,12 @@ sub process { "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } +# avoid lookup_symbol_name() + if ($line =~ /\blookup_symbol_name\b/) { + WARN("PREFER_PRINTK_FORMAT", + "If possible prefer %ps or %pS printk format string to print symbol name instead of using lookup_symbol_name()\n" . $herecurr); + } + # check for uses of printk_ratelimit if ($line =~ /\bprintk_ratelimit\s*\(/) { WARN("PRINTK_RATELIMITED",
Huh? nak.
lookup_symbol_name is used in the kernel a grand total of 3 times. 2 uses are kprobe, the other is fs/proc
None of the existing uses is equivalent to %ps
Why should this be applied?
Quoted 25 lines · Joe Perches
Quoted 5 lines · Helge Deller
In most cases people use
lookup_symbol_name()to resolve a kernel symbol and then print it viaprintk().In such cases using the %ps, %pS, %pSR or %pB printk formats are easier to use and thus should be preferred.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
scripts/checkpatch.pl sub process { · line 4328
Quoted 13 lines
scripts/checkpatch.pl +6
-0@@ -4317,6 +4317,12 @@ sub process { "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } +# avoid lookup_symbol_name() + if ($line =~ /\blookup_symbol_name\b/) { + WARN("PREFER_PRINTK_FORMAT", + "If possible prefer %ps or %pS printk format string to print symbol name instead of using lookup_symbol_name()\n" . $herecurr); + } + # check for uses of printk_ratelimit if ($line =~ /\bprintk_ratelimit\s*\(/) { WARN("PRINTK_RATELIMITED",Huh? nak.
Quoted 1 line
lookup_symbol_nameis used in the kernel a grand total of 3 times.
Yes, there were much more in the past which got fixed by patches I submitted.
Quoted 1 line
2 uses are kprobe, the other is fs/proc
Right. For fs/proc see:
https://lore.kernel.org/lkml/[email protected]/
Quoted 1 line
None of the existing uses is equivalent to %ps
Yes, those are the remaining legimate users.
Quoted 1 line
Why should this be applied?
... to prevent people to add new code with possibly unjustified use?
Helge
Joe Perches
maintainerQuoted 26 lines · Helge Deller
Quoted 25 lines · Joe Perches
Quoted 5 lines · Helge Deller
In most cases people use
lookup_symbol_name()to resolve a kernel symbol and then print it viaprintk().In such cases using the %ps, %pS, %pSR or %pB printk formats are easier to use and thus should be preferred.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
scripts/checkpatch.pl sub process { · line 4328
Quoted 13 lines
scripts/checkpatch.pl +6
-0@@ -4317,6 +4317,12 @@ sub process { "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } +# avoid lookup_symbol_name() + if ($line =~ /\blookup_symbol_name\b/) { + WARN("PREFER_PRINTK_FORMAT", + "If possible prefer %ps or %pS printk format string to print symbol name instead of using lookup_symbol_name()\n" . $herecurr); + } + # check for uses of printk_ratelimit if ($line =~ /\bprintk_ratelimit\s*\(/) { WARN("PRINTK_RATELIMITED",Huh? nak.
Quoted 3 lines
Quoted 1 line
lookup_symbol_nameis used in the kernel a grand total of 3 times.Yes, there were much more in the past which got fixed by patches I submitted.
Hi Helge.
Much more may be a bit of an overstatement.
I found 3 instances of lookup_symbol_name removals in 2 patches.
commit 36dbca148bf8e3b8658982aa2256bdc7ef040256
- lookup_symbol_name((ulong)pm_power_off, symname);
- lookup_symbol_name((ulong)pm_power_off, symname);
commit da88f9b3113620dcd30fc203236aa53d5430ee98
- if (lookup_symbol_name((unsigned long)sym, symname) < 0)
There's a tension between adding tests and newbies that consider checkpatch warnings as dicta that must be followed so there would be patches submitted eventually against the existing correct uses.
So thanks, but given the very few existing all correct uses of this function and the low probability of new uses I'd prefer not to apply this.
Quoted 43 lines · Joe Perches
Quoted 26 lines · Helge Deller
Quoted 25 lines · Joe Perches
Quoted 5 lines · Helge Deller
In most cases people use
lookup_symbol_name()to resolve a kernel symbol and then print it viaprintk().In such cases using the %ps, %pS, %pSR or %pB printk formats are easier to use and thus should be preferred.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
scripts/checkpatch.pl sub process { · line 4328
Quoted 13 lines
scripts/checkpatch.pl +6
-0@@ -4317,6 +4317,12 @@ sub process { "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } +# avoid lookup_symbol_name() + if ($line =~ /\blookup_symbol_name\b/) { + WARN("PREFER_PRINTK_FORMAT", + "If possible prefer %ps or %pS printk format string to print symbol name instead of using lookup_symbol_name()\n" . $herecurr); + } + # check for uses of printk_ratelimit if ($line =~ /\bprintk_ratelimit\s*\(/) { WARN("PRINTK_RATELIMITED",Huh? nak.
Quoted 3 lines
Quoted 1 line
lookup_symbol_nameis used in the kernel a grand total of 3 times.Yes, there were much more in the past which got fixed by patches I submitted.
Hi Helge.
Much more may be a bit of an overstatement.
I found 3 instances of
lookup_symbol_nameremovals in 2 patches.commit
36dbca148bf8e3b8658982aa2256bdc7ef040256(quoted diff) +0
-2- lookup_symbol_name((ulong)pm_power_off, symname); - lookup_symbol_name((ulong)pm_power_off, symname);commit
da88f9b3113620dcd30fc203236aa53d5430ee98(quoted diff) +0
-1- if (lookup_symbol_name((unsigned long)sym, symname) < 0)
Quoted 7 lines
There's a tension between adding tests and newbies that consider checkpatch warnings as dicta that must be followed so there would be patches submitted eventually against the existing correct uses.
So thanks, but given the very few existing all correct uses of this function and the low probability of new uses I'd prefer not to apply this.
Ok.
Thanks!
Helge