linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: add new warning when lookup_symbol_name() is used
@ 2020-12-17 17:11 Helge Deller
  2020-12-17 17:27 ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Helge Deller @ 2020-12-17 17:11 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches, linux-kernel

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.

Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fab38b493cef..0d5515a3d875 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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",

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

* Re: [PATCH] checkpatch: add new warning when lookup_symbol_name() is used
  2020-12-17 17:11 [PATCH] checkpatch: add new warning when lookup_symbol_name() is used Helge Deller
@ 2020-12-17 17:27 ` Joe Perches
  2020-12-17 17:42   ` Helge Deller
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2020-12-17 17:27 UTC (permalink / raw)
  To: Helge Deller, Andy Whitcroft, linux-kernel

On Thu, 2020-12-17 at 18:11 +0100, Helge Deller wrote:
> 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.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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?



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

* Re: [PATCH] checkpatch: add new warning when lookup_symbol_name() is used
  2020-12-17 17:27 ` Joe Perches
@ 2020-12-17 17:42   ` Helge Deller
  2020-12-17 18:15     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Helge Deller @ 2020-12-17 17:42 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft, linux-kernel

On 12/17/20 6:27 PM, Joe Perches wrote:
> On Thu, 2020-12-17 at 18:11 +0100, Helge Deller wrote:
>> 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.
> []
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
>> @@ -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.

Yes, there were much more in the past which got fixed by patches I submitted.

> 2 uses are kprobe, the other is fs/proc

Right. For fs/proc see:
https://lore.kernel.org/lkml/20201217165413.GA1959@ls3530.fritz.box/

> None of the existing uses is equivalent to %ps

Yes, those are the remaining legimate users.

> Why should this be applied?

... to prevent people to add new code with possibly unjustified use?

Helge

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

* Re: [PATCH] checkpatch: add new warning when lookup_symbol_name() is used
  2020-12-17 17:42   ` Helge Deller
@ 2020-12-17 18:15     ` Joe Perches
  2020-12-17 19:15       ` Helge Deller
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2020-12-17 18:15 UTC (permalink / raw)
  To: Helge Deller, Andy Whitcroft, linux-kernel

On Thu, 2020-12-17 at 18:42 +0100, Helge Deller wrote:
> On 12/17/20 6:27 PM, Joe Perches wrote:
> > On Thu, 2020-12-17 at 18:11 +0100, Helge Deller wrote:
> > > 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.
> > []
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > []
> > > @@ -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.
> 
> 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.



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

* Re: [PATCH] checkpatch: add new warning when lookup_symbol_name() is used
  2020-12-17 18:15     ` Joe Perches
@ 2020-12-17 19:15       ` Helge Deller
  0 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2020-12-17 19:15 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft, linux-kernel

On 12/17/20 7:15 PM, Joe Perches wrote:
> On Thu, 2020-12-17 at 18:42 +0100, Helge Deller wrote:
>> On 12/17/20 6:27 PM, Joe Perches wrote:
>>> On Thu, 2020-12-17 at 18:11 +0100, Helge Deller wrote:
>>>> 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.
>>> []
>>>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>>> []
>>>> @@ -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.
>>
>> 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.

Ok.

Thanks!
Helge

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

end of thread, other threads:[~2020-12-17 19:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 17:11 [PATCH] checkpatch: add new warning when lookup_symbol_name() is used Helge Deller
2020-12-17 17:27 ` Joe Perches
2020-12-17 17:42   ` Helge Deller
2020-12-17 18:15     ` Joe Perches
2020-12-17 19:15       ` Helge Deller

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).