* [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
@ 2022-11-03 1:17 Liao Chang
2022-11-03 2:37 ` Bagas Sanjaya
2022-11-03 13:39 ` Paolo Bonzini
0 siblings, 2 replies; 6+ messages in thread
From: Liao Chang @ 2022-11-03 1:17 UTC (permalink / raw)
To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa
Cc: x86, kvm, linux-kernel, liaochang1
Swap the 1st and 2nd arguments to be consistent with the usage of
kvcalloc().
Fixes: c9b8fecddb5b ("KVM: use kvcalloc for array allocations")
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
arch/x86/kvm/cpuid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 7065462378e2..b33c18b142c2 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1331,7 +1331,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (sanity_check_entries(entries, cpuid->nent, type))
return -EINVAL;
- array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
+ array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL);
if (!array.entries)
return -ENOMEM;
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
2022-11-03 1:17 [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc() Liao Chang
@ 2022-11-03 2:37 ` Bagas Sanjaya
2022-11-03 4:18 ` liaochang (A)
2022-11-03 13:39 ` Paolo Bonzini
1 sibling, 1 reply; 6+ messages in thread
From: Bagas Sanjaya @ 2022-11-03 2:37 UTC (permalink / raw)
To: Liao Chang
Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa, x86, kvm,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 277 bytes --]
On Thu, Nov 03, 2022 at 09:17:49AM +0800, Liao Chang wrote:
> Swap the 1st and 2nd arguments to be consistent with the usage of
> kvcalloc().
>
This isn't typofix as suggested from the patch subject, right?
--
An old man doll... just what I always wanted! - Clara
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
2022-11-03 2:37 ` Bagas Sanjaya
@ 2022-11-03 4:18 ` liaochang (A)
2022-11-03 5:21 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: liaochang (A) @ 2022-11-03 4:18 UTC (permalink / raw)
To: Bagas Sanjaya
Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa, x86, kvm,
linux-kernel
在 2022/11/3 10:37, Bagas Sanjaya 写道:
> This isn't typofix as suggested from the patch subject, right?
Well, since kvcalloc uses the product of 1st and 2nd argument to do allocation,
hence current code supposes to work well, but the usage is obviously no sense,
that is why i name it a 'typo' and make it correct ;)
--
BR,
Liao, Chang
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
2022-11-03 4:18 ` liaochang (A)
@ 2022-11-03 5:21 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2022-11-03 5:21 UTC (permalink / raw)
To: liaochang (A), Bagas Sanjaya
Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa, x86, kvm,
linux-kernel
On Thu, 2022-11-03 at 12:18 +0800, liaochang (A) wrote:
>
> 在 2022/11/3 10:37, Bagas Sanjaya 写道:
> > This isn't typofix as suggested from the patch subject, right?
>
> Well, since kvcalloc uses the product of 1st and 2nd argument to do allocation,
> hence current code supposes to work well, but the usage is obviously no sense,
> that is why i name it a 'typo' and make it correct ;)
>
Seems there are several of these typo/defects.
$ git grep -P 'calloc\s*\(\s*sizeof'
arch/x86/kvm/cpuid.c: array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
drivers/gpu/drm/nouveau/nouveau_svm.c: buffer->fault = kvcalloc(sizeof(*buffer->fault), buffer->entries, GFP_KERNEL);
drivers/scsi/bfa/bfad_bsg.c: buf_base = kcalloc(sizeof(struct bfad_buf_info) +
drivers/soc/fsl/dpio/dpio-service.c: ed = kcalloc(sizeof(struct qbman_eq_desc), 32, GFP_KERNEL);
fs/btrfs/send.c: sctx->clone_roots = kvcalloc(sizeof(*sctx->clone_roots),
kernel/bpf/bpf_local_storage.c: smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets,
kernel/watch_queue.c: pages = kcalloc(sizeof(struct page *), nr_pages, GFP_KERNEL);
tools/lib/bpf/libbpf.c: gen = calloc(sizeof(*gen), 1);
tools/objtool/check.c: struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
tools/objtool/check.c: file->pv_ops = calloc(sizeof(struct pv_state), nr);
tools/perf/builtin-record.c: rec->switch_output.filenames = calloc(sizeof(char *),
tools/perf/util/bpf-loader.c: priv = calloc(sizeof(*priv), 1);
tools/perf/util/hist.c: he->res_samples = calloc(sizeof(struct res_sample),
tools/perf/util/metricgroup.c: metric_events = calloc(sizeof(void *), ids_size + 1);
tools/perf/util/stat-shadow.c: metric_events = calloc(sizeof(struct evsel *),
tools/perf/util/synthetic-events.c: synthesize_threads = calloc(sizeof(pthread_t), thread_nr);
tools/perf/util/synthetic-events.c: args = calloc(sizeof(*args), thread_nr);
tools/testing/selftests/arm64/fp/fp-stress.c: children = calloc(sizeof(*children), tests);
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c: link = calloc(sizeof(struct bpf_link *), prog_cnt);
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c: prog = calloc(sizeof(struct bpf_program *), prog_cnt);
tools/testing/selftests/bpf/test_progs.c: dispatcher_threads = calloc(sizeof(pthread_t), env.workers);
tools/testing/selftests/bpf/test_progs.c: data = calloc(sizeof(struct dispatch_data), env.workers);
tools/testing/selftests/bpf/test_progs.c: env.worker_current_test = calloc(sizeof(int), env.workers);
tools/testing/selftests/bpf/test_progs.c: env.worker_pids = calloc(sizeof(__pid_t), env.workers);
tools/testing/selftests/bpf/test_progs.c: env.worker_socks = calloc(sizeof(int), env.workers);
tools/testing/selftests/memfd/fuse_test.c: zero = calloc(sizeof(*zero), mfd_def_size);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
2022-11-03 1:17 [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc() Liao Chang
2022-11-03 2:37 ` Bagas Sanjaya
@ 2022-11-03 13:39 ` Paolo Bonzini
2022-11-04 4:06 ` liaochang (A)
1 sibling, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2022-11-03 13:39 UTC (permalink / raw)
To: Liao Chang, seanjc, tglx, mingo, bp, dave.hansen, hpa
Cc: x86, kvm, linux-kernel, Joe Perches
On 11/3/22 02:17, Liao Chang wrote:
> Swap the 1st and 2nd arguments to be consistent with the usage of
> kvcalloc().
>
> Fixes: c9b8fecddb5b ("KVM: use kvcalloc for array allocations")
> Signed-off-by: Liao Chang<liaochang1@huawei.com>
> ---
> arch/x86/kvm/cpuid.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 7065462378e2..b33c18b142c2 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1331,7 +1331,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
> if (sanity_check_entries(entries, cpuid->nent, type))
> return -EINVAL;
>
> - array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
> + array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL);
> if (!array.entries)
> return -ENOMEM;
>
It doesn't make any difference, but scripts/checkpatch.pl checks it so
let's fix the sole occurrence in KVM.
However, please send a patch to scripts/checkpatch.pl to include calloc(),
kvmalloc_array and kvcalloc() in the matched functions:
# check for alloc argument mismatch
if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
WARN("ALLOC_ARRAY_ARGS",
"$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
}
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc()
2022-11-03 13:39 ` Paolo Bonzini
@ 2022-11-04 4:06 ` liaochang (A)
0 siblings, 0 replies; 6+ messages in thread
From: liaochang (A) @ 2022-11-04 4:06 UTC (permalink / raw)
To: Paolo Bonzini, seanjc, tglx, mingo, bp, dave.hansen, hpa
Cc: x86, kvm, linux-kernel, Joe Perches
在 2022/11/3 21:39, Paolo Bonzini 写道:
> On 11/3/22 02:17, Liao Chang wrote:
>> Swap the 1st and 2nd arguments to be consistent with the usage of
>> kvcalloc().
>>
>> Fixes: c9b8fecddb5b ("KVM: use kvcalloc for array allocations")
>> Signed-off-by: Liao Chang<liaochang1@huawei.com>
>> ---
>> arch/x86/kvm/cpuid.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> index 7065462378e2..b33c18b142c2 100644
>> --- a/arch/x86/kvm/cpuid.c
>> +++ b/arch/x86/kvm/cpuid.c
>> @@ -1331,7 +1331,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>> if (sanity_check_entries(entries, cpuid->nent, type))
>> return -EINVAL;
>> - array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
>> + array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL);
>> if (!array.entries)
>> return -ENOMEM;
>>
>
> It doesn't make any difference, but scripts/checkpatch.pl checks it so
> let's fix the sole occurrence in KVM.
>
> However, please send a patch to scripts/checkpatch.pl to include calloc(),
> kvmalloc_array and kvcalloc() in the matched functions:
>
> # check for alloc argument mismatch
> if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
> WARN("ALLOC_ARRAY_ARGS",
> "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
> }
I ready send a patch to enhance the checking for array allocator family,
please check out patch "checkpatch: Add check for array allocator family argument order".
Thanks.
>
>
> Paolo
>
>
> .
--
BR,
Liao, Chang
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-04 4:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-03 1:17 [PATCH 2/2] KVM: x86: Fix a typo about the usage of kvcalloc() Liao Chang
2022-11-03 2:37 ` Bagas Sanjaya
2022-11-03 4:18 ` liaochang (A)
2022-11-03 5:21 ` Joe Perches
2022-11-03 13:39 ` Paolo Bonzini
2022-11-04 4:06 ` liaochang (A)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox