All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: ignore warning designated initializers using NR_CPUS
@ 2020-12-30  4:13 Peng Wang
  2020-12-30  5:35 ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Peng Wang @ 2020-12-30  4:13 UTC (permalink / raw)
  To: apw, joe; +Cc: linux-kernel

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,
        },
	...
}

Signed-off-by: Peng Wang <rocking@linux.alibaba.com>
---
 scripts/checkpatch.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0008530..da8fc48 100755
--- 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);
-- 
2.9.5


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

* Re: [PATCH] checkpatch: ignore warning designated initializers using NR_CPUS
  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
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joe Perches @ 2020-12-30  5:35 UTC (permalink / raw)
  To: Peng Wang, apw; +Cc: linux-kernel

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)

$ 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/

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,



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

* Re: [PATCH] checkpatch: ignore warning designated initializers using NR_CPUS
  2020-12-30  5:35 ` Joe Perches
@ 2020-12-30  7:10   ` Peng Wang
  2020-12-30  7:14   ` [PATCH v2] " Peng Wang
  2020-12-30 12:29   ` [PATCH v3] " Peng Wang
  2 siblings, 0 replies; 7+ messages in thread
From: Peng Wang @ 2020-12-30  7:10 UTC (permalink / raw)
  To: Joe Perches, apw; +Cc: linux-kernel

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,
> 

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

* [PATCH v2] checkpatch: ignore warning designated initializers using NR_CPUS
  2020-12-30  5:35 ` Joe Perches
  2020-12-30  7:10   ` Peng Wang
@ 2020-12-30  7:14   ` Peng Wang
  2020-12-30 12:16     ` Joe Perches
  2020-12-30 12:29   ` [PATCH v3] " Peng Wang
  2 siblings, 1 reply; 7+ messages in thread
From: Peng Wang @ 2020-12-30  7:14 UTC (permalink / raw)
  To: apw, joe; +Cc: linux-kernel

Some max_length wants to hold as large room as possible to
ensure enough size to tackle with the biggest NR_CPUS.
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,
        },
	...
}

Signed-off-by: Peng Wang <rocking@linux.alibaba.com>
---
 scripts/checkpatch.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0008530..fdbbab3 100755
--- 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*\.\w+\s*=\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);
-- 
2.9.5


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

* Re: [PATCH v2] checkpatch: ignore warning designated initializers using NR_CPUS
  2020-12-30  7:14   ` [PATCH v2] " Peng Wang
@ 2020-12-30 12:16     ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2020-12-30 12:16 UTC (permalink / raw)
  To: Peng Wang, apw, Andrew Morton; +Cc: linux-kernel

On Wed, 2020-12-30 at 15:14 +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.
> 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
> +

Please remove this empty line, other than that, looks OK to me.

Andrew?  Care to take this and remove the empty line or wait for v3?

>  		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*\.\w+\s*=\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);



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

* [PATCH v3] checkpatch: ignore warning designated initializers using NR_CPUS
  2020-12-30  5:35 ` Joe Perches
  2020-12-30  7:10   ` Peng Wang
  2020-12-30  7:14   ` [PATCH v2] " Peng Wang
@ 2020-12-30 12:29   ` Peng Wang
  2020-12-30 12:38     ` Joe Perches
  2 siblings, 1 reply; 7+ messages in thread
From: Peng Wang @ 2020-12-30 12:29 UTC (permalink / raw)
  To: apw, joe; +Cc: linux-kernel

Some max_length wants to hold as large room as possible to
ensure enough size to tackle with the biggest NR_CPUS.
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,
        },
	...
}

Signed-off-by: Peng Wang <rocking@linux.alibaba.com>
---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 92e888e..6f112fb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7028,12 +7028,14 @@ 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*\.\w+\s*=\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);
-- 
2.9.5


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

* Re: [PATCH v3] checkpatch: ignore warning designated initializers using NR_CPUS
  2020-12-30 12:29   ` [PATCH v3] " Peng Wang
@ 2020-12-30 12:38     ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2020-12-30 12:38 UTC (permalink / raw)
  To: Peng Wang, apw, Andrew Morton; +Cc: linux-kernel

On Wed, 2020-12-30 at 20:29 +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.
> 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,
>         },
> 	...
> }
> 
> Signed-off-by: Peng Wang <rocking@linux.alibaba.com>
> ---
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7028,12 +7028,14 @@ 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*\.\w+\s*=\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);

Thanks.

Acked-by: Joe Perches <joe@perches.com>



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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.