* [PATCH -next v2] checkpatch: Add check for array allocator family argument order
@ 2022-11-04 7:05 Liao Chang
2022-11-04 8:35 ` Lukas Bulwahn
2022-11-04 17:08 ` Christophe JAILLET
0 siblings, 2 replies; 8+ messages in thread
From: Liao Chang @ 2022-11-04 7:05 UTC (permalink / raw)
To: apw, joe, dwaipayanray1, lukas.bulwahn
Cc: linux-kernel, liaochang1, bagasdotme, pbonzini
These array allocator family are sometimes misused with the first and
second arguments switchted.
Same issue with calloc, kvcalloc, kvmalloc_array etc.
Bleat if sizeof is the first argument.
Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
Signed-off-by: Liao Chang <liaochang1@huawei.com>
Acked-by: Joe Perches <joe@perches.com>
---
v2:
1. Acked-by Joe Perches.
2. Use lore links in Link tag.
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1e5e66ae5a52..a9a9dc277cff 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7128,7 +7128,7 @@ sub process {
}
# check for alloc argument mismatch
- if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
+ if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
WARN("ALLOC_ARRAY_ARGS",
"$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-04 7:05 [PATCH -next v2] checkpatch: Add check for array allocator family argument order Liao Chang
@ 2022-11-04 8:35 ` Lukas Bulwahn
2022-11-04 14:33 ` Joe Perches
2022-11-07 1:25 ` liaochang (A)
2022-11-04 17:08 ` Christophe JAILLET
1 sibling, 2 replies; 8+ messages in thread
From: Lukas Bulwahn @ 2022-11-04 8:35 UTC (permalink / raw)
To: Liao Chang; +Cc: apw, joe, dwaipayanray1, linux-kernel, bagasdotme, pbonzini
On Fri, Nov 4, 2022 at 8:08 AM Liao Chang <liaochang1@huawei.com> wrote:
>
> These array allocator family are sometimes misused with the first and
> second arguments switchted.
Just a nit:
s/switchted/switched/
But probably you actually mean "swapped". I think there is a slight
difference between the two words, "switched" and "swapped". And here
the arguments are swapped. Note: I am also not a native speaker.
For the implementation change:
Acked-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
How many new findings are now identified with this extended check on
linux-next? Could you run checkpatch on all files of linux-next and
share the new findings? Then we can do a quick scan if some instances
should be immediately fixed or some janitor should follow through with
such a task.
Lukas
>
> Same issue with calloc, kvcalloc, kvmalloc_array etc.
>
> Bleat if sizeof is the first argument.
>
> Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Acked-by: Joe Perches <joe@perches.com>
> ---
> v2:
> 1. Acked-by Joe Perches.
> 2. Use lore links in Link tag.
>
> ---
> scripts/checkpatch.pl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 1e5e66ae5a52..a9a9dc277cff 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -7128,7 +7128,7 @@ sub process {
> }
>
> # check for alloc argument mismatch
> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
> + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
> WARN("ALLOC_ARRAY_ARGS",
> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
> }
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-04 8:35 ` Lukas Bulwahn
@ 2022-11-04 14:33 ` Joe Perches
2022-11-07 1:25 ` liaochang (A)
1 sibling, 0 replies; 8+ messages in thread
From: Joe Perches @ 2022-11-04 14:33 UTC (permalink / raw)
To: Lukas Bulwahn, Liao Chang
Cc: apw, dwaipayanray1, linux-kernel, bagasdotme, pbonzini
On Fri, 2022-11-04 at 09:35 +0100, Lukas Bulwahn wrote:
> On Fri, Nov 4, 2022 at 8:08 AM Liao Chang <liaochang1@huawei.com> wrote:
> >
> > These array allocator family are sometimes misused with the first and
> > second arguments switchted.
>
> Just a nit:
>
> s/switchted/switched/
>
> But probably you actually mean "swapped". I think there is a slight
> difference between the two words, "switched" and "swapped". And here
> the arguments are swapped. Note: I am also not a native speaker.
>
> For the implementation change:
>
> Acked-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
>
> How many new findings are now identified with this extended check on
> linux-next? Could you run checkpatch on all files of linux-next and
> share the new findings? Then we can do a quick scan if some instances
> should be immediately fixed or some janitor should follow through with
> such a task.
There are ~25.
It's fairly trivial Lukas and only cosmetic.
https://lore.kernel.org/lkml/d92ada3062bc1c3a7557bfa0499fc4a8cee3aa10.camel@perches.com/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-04 7:05 [PATCH -next v2] checkpatch: Add check for array allocator family argument order Liao Chang
2022-11-04 8:35 ` Lukas Bulwahn
@ 2022-11-04 17:08 ` Christophe JAILLET
2022-11-05 17:24 ` Joe Perches
1 sibling, 1 reply; 8+ messages in thread
From: Christophe JAILLET @ 2022-11-04 17:08 UTC (permalink / raw)
To: Liao Chang, apw, joe, dwaipayanray1, lukas.bulwahn
Cc: linux-kernel, bagasdotme, pbonzini
Le 04/11/2022 à 08:05, Liao Chang a écrit :
> These array allocator family are sometimes misused with the first and
> second arguments switchted.
>
> Same issue with calloc, kvcalloc, kvmalloc_array etc.
>
> Bleat if sizeof is the first argument.
>
> Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Acked-by: Joe Perches <joe@perches.com>
> ---
> v2:
> 1. Acked-by Joe Perches.
> 2. Use lore links in Link tag.
>
> ---
> scripts/checkpatch.pl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 1e5e66ae5a52..a9a9dc277cff 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -7128,7 +7128,7 @@ sub process {
> }
>
> # check for alloc argument mismatch
> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
> + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
> WARN("ALLOC_ARRAY_ARGS",
> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
> }
Hi,
Should the devm_ and not devm_ cases be separated?
In the devm_case, sizeof will never be just after the first '('.
CJ
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-04 17:08 ` Christophe JAILLET
@ 2022-11-05 17:24 ` Joe Perches
2022-11-05 21:36 ` Christophe JAILLET
0 siblings, 1 reply; 8+ messages in thread
From: Joe Perches @ 2022-11-05 17:24 UTC (permalink / raw)
To: Christophe JAILLET, Liao Chang, apw, dwaipayanray1,
lukas.bulwahn, Andrew Morton
Cc: linux-kernel, bagasdotme, pbonzini
On Fri, 2022-11-04 at 18:08 +0100, Christophe JAILLET wrote:
> Le 04/11/2022 à 08:05, Liao Chang a écrit :
> > These array allocator family are sometimes misused with the first and
> > second arguments switchted.
> >
> > Same issue with calloc, kvcalloc, kvmalloc_array etc.
> >
> > Bleat if sizeof is the first argument.
> >
> > Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
> > Signed-off-by: Liao Chang <liaochang1@huawei.com>
> > Acked-by: Joe Perches <joe@perches.com>
> > ---
> > v2:
> > 1. Acked-by Joe Perches.
> > 2. Use lore links in Link tag.
> >
> > ---
> > scripts/checkpatch.pl | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 1e5e66ae5a52..a9a9dc277cff 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -7128,7 +7128,7 @@ sub process {
> > }
> >
> > # check for alloc argument mismatch
> > - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
> > + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
> > WARN("ALLOC_ARRAY_ARGS",
> > "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
> > }
>
> Hi,
>
> Should the devm_ and not devm_ cases be separated?
>
> In the devm_case, sizeof will never be just after the first '('.
Right.
Likely this works better:
---
scripts/checkpatch.pl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7be93c3df2bcb..7f37976a9f8b5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7145,12 +7145,18 @@ sub process {
"Reusing the krealloc arg is almost always a bug\n" . $herecurr);
}
-# check for alloc argument mismatch
- if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
+# check for alloc argument mismatch in alloc functions
+ if ($line =~ /\b(((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
WARN("ALLOC_ARRAY_ARGS",
"$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
}
+# check for alloc argument mismatch in devm_ alloc functions
+ if ($line =~ /\b(devm_((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*$FuncArg\s*,\s*sizeof\b/) {
+ WARN("ALLOC_ARRAY_ARGS",
+ "$1 uses number as second arg, sizeof is generally wrong\n" . $herecurr);
+ }
+
# check for multiple semicolons
if ($line =~ /;\s*;\s*$/) {
if (WARN("ONE_SEMICOLON",
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-05 17:24 ` Joe Perches
@ 2022-11-05 21:36 ` Christophe JAILLET
2022-11-07 1:25 ` liaochang (A)
0 siblings, 1 reply; 8+ messages in thread
From: Christophe JAILLET @ 2022-11-05 21:36 UTC (permalink / raw)
To: Joe Perches, Liao Chang, apw, dwaipayanray1, lukas.bulwahn,
Andrew Morton
Cc: linux-kernel, bagasdotme, pbonzini
Le 05/11/2022 à 18:24, Joe Perches a écrit :
> On Fri, 2022-11-04 at 18:08 +0100, Christophe JAILLET wrote:
>> Le 04/11/2022 à 08:05, Liao Chang a écrit :
>>> These array allocator family are sometimes misused with the first and
>>> second arguments switchted.
>>>
>>> Same issue with calloc, kvcalloc, kvmalloc_array etc.
>>>
>>> Bleat if sizeof is the first argument.
>>>
>>> Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
>>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>>> Acked-by: Joe Perches <joe@perches.com>
>>> ---
>>> v2:
>>> 1. Acked-by Joe Perches.
>>> 2. Use lore links in Link tag.
>>>
>>> ---
>>> scripts/checkpatch.pl | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>>> index 1e5e66ae5a52..a9a9dc277cff 100755
>>> --- a/scripts/checkpatch.pl
>>> +++ b/scripts/checkpatch.pl
>>> @@ -7128,7 +7128,7 @@ sub process {
>>> }
>>>
>>> # check for alloc argument mismatch
>>> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
>>> + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
>>> WARN("ALLOC_ARRAY_ARGS",
>>> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
>>> }
>> Hi,
>>
>> Should the devm_ and not devm_ cases be separated?
>>
>> In the devm_case, sizeof will never be just after the first '('.
> Right.
>
> Likely this works better:
> ---
> scripts/checkpatch.pl | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7be93c3df2bcb..7f37976a9f8b5 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -7145,12 +7145,18 @@ sub process {
> "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
> }
>
> -# check for alloc argument mismatch
> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
> +# check for alloc argument mismatch in alloc functions
> + if ($line =~ /\b(((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
> WARN("ALLOC_ARRAY_ARGS",
> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
> }
>
> +# check for alloc argument mismatch in devm_ alloc functions
> + if ($line =~ /\b(devm_((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*$FuncArg\s*,\s*sizeof\b/) {
> + WARN("ALLOC_ARRAY_ARGS",
> + "$1 uses number as second arg, sizeof is generally wrong\n" . $herecurr);
> + }
> +
> # check for multiple semicolons
> if ($line =~ /;\s*;\s*$/) {
> if (WARN("ONE_SEMICOLON",
>
+1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-04 8:35 ` Lukas Bulwahn
2022-11-04 14:33 ` Joe Perches
@ 2022-11-07 1:25 ` liaochang (A)
1 sibling, 0 replies; 8+ messages in thread
From: liaochang (A) @ 2022-11-07 1:25 UTC (permalink / raw)
To: Lukas Bulwahn; +Cc: apw, joe, dwaipayanray1, linux-kernel, bagasdotme, pbonzini
在 2022/11/4 16:35, Lukas Bulwahn 写道:
> On Fri, Nov 4, 2022 at 8:08 AM Liao Chang <liaochang1@huawei.com> wrote:
>>
>> These array allocator family are sometimes misused with the first and
>> second arguments switchted.
>
> Just a nit:
>
> s/switchted/switched/
>
> But probably you actually mean "swapped". I think there is a slight
> difference between the two words, "switched" and "swapped". And here
> the arguments are swapped. Note: I am also not a native speaker.
>
> For the implementation change:
>
> Acked-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
>
> How many new findings are now identified with this extended check on
> linux-next? Could you run checkpatch on all files of linux-next and
> share the new findings? Then we can do a quick scan if some instances
> should be immediately fixed or some janitor should follow through with
> such a task.
The scan result for v6.1-rc3:
./kernel/watch_queue.c:276: pages = kcalloc(sizeof(struct page *), nr_pages, GFP_KERNEL);
./virt/kvm/kvm_main.c:411: mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
./tools/objtool/check.c:288: struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
./tools/objtool/check.c:517: file->pv_ops = calloc(sizeof(struct pv_state), nr);
./kernel/bpf/bpf_local_storage.c:623: smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets,
./tools/perf/builtin-record.c:4076: rec->switch_output.filenames = calloc(sizeof(char *),
./fs/btrfs/send.c:7913: sctx->clone_roots = kvcalloc(sizeof(*sctx->clone_roots),
./drivers/scsi/bfa/bfad_bsg.c:3247: buf_base = kcalloc(sizeof(struct bfad_buf_info) +
./sound/core/seq/seq_memory.c:379: cellptr = kvmalloc_array(sizeof(struct snd_seq_event_cell), pool->size,
./tools/lib/bpf/libbpf.c:8220: gen = calloc(sizeof(*gen), 1);
./tools/perf/util/metricgroup.c:269: metric_events = calloc(sizeof(void *), ids_size + 1);
./tools/perf/util/hist.c:492: he->res_samples = calloc(sizeof(struct res_sample),
./tools/perf/util/bpf-loader.c:574: priv = calloc(sizeof(*priv), 1);
./tools/perf/util/synthetic-events.c:1040: synthesize_threads = calloc(sizeof(pthread_t), thread_nr);
./tools/perf/util/synthetic-events.c:1044: args = calloc(sizeof(*args), thread_nr);
./tools/perf/util/stat-shadow.c:390: metric_events = calloc(sizeof(struct evsel *),
./drivers/soc/fsl/dpio/dpio-service.c:526: ed = kcalloc(sizeof(struct qbman_eq_desc), 32, GFP_KERNEL);
./drivers/gpu/drm/nouveau/nouveau_svm.c:1000: buffer->fault = kvcalloc(sizeof(*buffer->fault), buffer->entries, GFP_KERNEL);
./tools/testing/selftests/memfd/fuse_test.c:257: zero = calloc(sizeof(*zero), mfd_def_size);
./tools/testing/selftests/bpf/test_progs.c:1324: dispatcher_threads = calloc(sizeof(pthread_t), env.workers);
./tools/testing/selftests/bpf/test_progs.c:1325: data = calloc(sizeof(struct dispatch_data), env.workers);
./tools/testing/selftests/bpf/test_progs.c:1327: env.worker_current_test = calloc(sizeof(int), env.workers);
./tools/testing/selftests/bpf/test_progs.c:1642: env.worker_pids = calloc(sizeof(__pid_t), env.workers);
./tools/testing/selftests/bpf/test_progs.c:1643: env.worker_socks = calloc(sizeof(int), env.workers);
./tools/testing/selftests/arm64/fp/fp-stress.c:458: children = calloc(sizeof(*children), tests);
./tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c:87: link = calloc(sizeof(struct bpf_link *), prog_cnt);
./tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c:91: prog = calloc(sizeof(struct bpf_program *), prog_cnt);
>
> Lukas
>
>>
>> Same issue with calloc, kvcalloc, kvmalloc_array etc.
>>
>> Bleat if sizeof is the first argument.
>>
>> Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>> Acked-by: Joe Perches <joe@perches.com>
>> ---
>> v2:
>> 1. Acked-by Joe Perches.
>> 2. Use lore links in Link tag.
>>
>> ---
>> scripts/checkpatch.pl | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 1e5e66ae5a52..a9a9dc277cff 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -7128,7 +7128,7 @@ sub process {
>> }
>>
>> # check for alloc argument mismatch
>> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
>> + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
>> WARN("ALLOC_ARRAY_ARGS",
>> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
>> }
>> --
>> 2.17.1
>>
> .
--
BR,
Liao, Chang
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next v2] checkpatch: Add check for array allocator family argument order
2022-11-05 21:36 ` Christophe JAILLET
@ 2022-11-07 1:25 ` liaochang (A)
0 siblings, 0 replies; 8+ messages in thread
From: liaochang (A) @ 2022-11-07 1:25 UTC (permalink / raw)
To: Christophe JAILLET, Joe Perches, apw, dwaipayanray1,
lukas.bulwahn, Andrew Morton
Cc: linux-kernel, bagasdotme, pbonzini
在 2022/11/6 5:36, Christophe JAILLET 写道:
>
> Le 05/11/2022 à 18:24, Joe Perches a écrit :
>> On Fri, 2022-11-04 at 18:08 +0100, Christophe JAILLET wrote:
>>> Le 04/11/2022 à 08:05, Liao Chang a écrit :
>>>> These array allocator family are sometimes misused with the first and
>>>> second arguments switchted.
>>>>
>>>> Same issue with calloc, kvcalloc, kvmalloc_array etc.
>>>>
>>>> Bleat if sizeof is the first argument.
>>>>
>>>> Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@redhat.com/
>>>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>>>> Acked-by: Joe Perches <joe@perches.com>
>>>> ---
>>>> v2:
>>>> 1. Acked-by Joe Perches.
>>>> 2. Use lore links in Link tag.
>>>>
>>>> ---
>>>> scripts/checkpatch.pl | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>>>> index 1e5e66ae5a52..a9a9dc277cff 100755
>>>> --- a/scripts/checkpatch.pl
>>>> +++ b/scripts/checkpatch.pl
>>>> @@ -7128,7 +7128,7 @@ sub process {
>>>> }
>>>> # check for alloc argument mismatch
>>>> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
>>>> + if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
>>>> WARN("ALLOC_ARRAY_ARGS",
>>>> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
>>>> }
>>> Hi,
>>>
>>> Should the devm_ and not devm_ cases be separated?
>>>
>>> In the devm_case, sizeof will never be just after the first '('.
>> Right.
>>
>> Likely this works better:
>> ---
>> scripts/checkpatch.pl | 10 ++++++++--
>> 1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 7be93c3df2bcb..7f37976a9f8b5 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -7145,12 +7145,18 @@ sub process {
>> "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
>> }
>> -# check for alloc argument mismatch
>> - if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
>> +# check for alloc argument mismatch in alloc functions
>> + if ($line =~ /\b(((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
>> WARN("ALLOC_ARRAY_ARGS",
>> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
>> }
>> +# check for alloc argument mismatch in devm_ alloc functions
>> + if ($line =~ /\b(devm_((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*$FuncArg\s*,\s*sizeof\b/) {
>> + WARN("ALLOC_ARRAY_ARGS",
>> + "$1 uses number as second arg, sizeof is generally wrong\n" . $herecurr);
>> + }
>> +
>> # check for multiple semicolons
>> if ($line =~ /;\s*;\s*$/) {
>> if (WARN("ONE_SEMICOLON",
>>
> +1
>
+1, thanks.
BTW, i find the v2 has been added to the -mm mm-nonmm-unstable branch,
do i need to submit new version includes above change?
>
> .
--
BR,
Liao, Chang
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-11-07 1:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 7:05 [PATCH -next v2] checkpatch: Add check for array allocator family argument order Liao Chang
2022-11-04 8:35 ` Lukas Bulwahn
2022-11-04 14:33 ` Joe Perches
2022-11-07 1:25 ` liaochang (A)
2022-11-04 17:08 ` Christophe JAILLET
2022-11-05 17:24 ` Joe Perches
2022-11-05 21:36 ` Christophe JAILLET
2022-11-07 1:25 ` liaochang (A)
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.