public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peng Wang <rocking@linux.alibaba.com>
To: Joe Perches <joe@perches.com>, apw@canonical.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: ignore warning designated initializers using NR_CPUS
Date: Wed, 30 Dec 2020 15:10:38 +0800	[thread overview]
Message-ID: <8564dd96-7ad2-c603-4ff4-ab85caad2852@linux.alibaba.com> (raw)
In-Reply-To: <5ca6c2d28f6cf091a676f8e7d8f14a933da0b267.camel@perches.com>

Hi, Joe

On 12/30/20 1:35 PM, , Joe Perches wrote:
> On Wed, 2020-12-30 at 12:13 +0800, Peng Wang wrote:
>> Some max_length wants to hold as large room as possible to
>> ensure enough size to tackle with the biggest NR_CPUS. As
>> an example below:
>>
>> kernel/cgroup/cpuset.c:
>> static struct cftype legacy_files[] = {
>>          {
>>                  .name = "cpus",
>>                  .seq_show = cpuset_common_seq_show,
>>                  .write = cpuset_write_resmask,
>>                  .max_write_len = (100U + 6 * NR_CPUS),
>>                  .private = FILE_CPULIST,
>>          },
>> 	...
>> }
> []
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
>> @@ -7022,12 +7022,15 @@ sub process {
>>   
>>
>>   # use of NR_CPUS is usually wrong
>>   # ignore definitions of NR_CPUS and usage to define arrays as likely right
>> +# ignore designated initializers using NR_CPUS
>> +
>>   		if ($line =~ /\bNR_CPUS\b/ &&
>>   		    $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
>>   		    $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
>>   		    $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
>>   		    $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
>> -		    $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
>> +		    $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/ &&
>> +		    $line !~ /\s*\..*=.*\bNR_CPUS\b.*,$/)
>>   		{
>>   			WARN("NR_CPUS",
>>   			     "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
> 
> I wonder if it's worth it as there just aren't many of these: (6 total)

It does not look that much, but checkpatch.pl makes warning on this 
especially when "0 errors, 0 warnings" is needed.

> 
> $ git grep -P '\..*=.*\bNR_CPUS\b.*,\s*$'
> drivers/firmware/efi/efi.c:     .cpu_bitmap             = { [BITS_TO_LONGS(NR__CPUS)] = 0},
> drivers/infiniband/hw/hfi1/sdma.c:      .max_size = NR_CPUS,
> init/init_task.c:       .nr_cpus_allowed= NR_CPUS,
> kernel/cgroup/cpuset.c:         .max_write_len = (100U + 6 * NR_CPUS),
> kernel/cgroup/cpuset.c:         .max_write_len = (100U + 6 * NR_CPUS),
> kernel/sysctl.c:                .maxlen         = NR_CPUS,
> 
> It also seems it might be more sensible as:
> 
> 	$line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/

Aha, this is better!
Will send a v2 patch including this if you don't mind, Thanks.

> 
> Which finds a couple more:
> 
> $ git grep -P '^\s*\.\w+\s*=\s*.*\bNR_CPUS\b'
> arch/arm64/include/asm/processor.h:     .fpsimd_cpu = NR_CPUS,                  \
> arch/powerpc/kernel/prom_init.c:                .max_cpus = cpu_to_be32(NR_CPUS),       /* number of cores supported */
> drivers/firmware/efi/efi.c:     .cpu_bitmap             = { [BITS_TO_LONGS(NR_CPUS)] = 0},
> drivers/infiniband/hw/hfi1/sdma.c:      .max_size = NR_CPUS,
> init/init_task.c:       .nr_cpus_allowed= NR_CPUS,
> kernel/cgroup/cpuset.c:         .max_write_len = (100U + 6 * NR_CPUS),
> kernel/cgroup/cpuset.c:         .max_write_len = (100U + 6 * NR_CPUS),
> kernel/sysctl.c:                .maxlen         = NR_CPUS,
> 

  reply	other threads:[~2020-12-30  7:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30  4:13 [PATCH] checkpatch: ignore warning designated initializers using NR_CPUS Peng Wang
2020-12-30  5:35 ` Joe Perches
2020-12-30  7:10   ` Peng Wang [this message]
2020-12-30  7:14   ` [PATCH v2] " Peng Wang
2020-12-30 12:16     ` Joe Perches
2020-12-30 12:29   ` [PATCH v3] " Peng Wang
2020-12-30 12:38     ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8564dd96-7ad2-c603-4ff4-ab85caad2852@linux.alibaba.com \
    --to=rocking@linux.alibaba.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox