arch/x86/events/amd/uncore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Dynamic size calculations should not be performed in allocator
function arguments due to overflow risk.
Use kcalloc() instead of multiplication in the first argument
of kzalloc().
Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
arch/x86/events/amd/uncore.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
index e8b6af199c738eb00b..d08e3054461f2ca07a 100644
--- a/arch/x86/events/amd/uncore.c
+++ b/arch/x86/events/amd/uncore.c
@@ -1036,11 +1036,11 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
group_num_pmus[gid] = hweight32(info.split.aux_data);
group_num_pmcs[gid] = info.split.num_pmcs;
uncore->num_pmus += group_num_pmus[gid];
}
- uncore->pmus = kzalloc(sizeof(*uncore->pmus) * uncore->num_pmus,
+ uncore->pmus = kcalloc(uncore->num_pmus, sizeof(*uncore->pmus),
GFP_KERNEL);
if (!uncore->pmus) {
uncore->num_pmus = 0;
goto done;
}
--
Cheers,
Joey Pabalinas
On 9/13/2025 2:35 PM, Joey Pabalinas wrote: > Dynamic size calculations should not be performed in allocator > function arguments due to overflow risk. > > Use kcalloc() instead of multiplication in the first argument > of kzalloc(). > > Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com> > --- > arch/x86/events/amd/uncore.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c > index e8b6af199c738eb00b..d08e3054461f2ca07a 100644 > --- a/arch/x86/events/amd/uncore.c > +++ b/arch/x86/events/amd/uncore.c > @@ -1036,11 +1036,11 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu) > group_num_pmus[gid] = hweight32(info.split.aux_data); > group_num_pmcs[gid] = info.split.num_pmcs; > uncore->num_pmus += group_num_pmus[gid]; > } > > - uncore->pmus = kzalloc(sizeof(*uncore->pmus) * uncore->num_pmus, > + uncore->pmus = kcalloc(uncore->num_pmus, sizeof(*uncore->pmus), > GFP_KERNEL); > if (!uncore->pmus) { > uncore->num_pmus = 0; > goto done; > } LGTM. Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
© 2016 - 2025 Red Hat, Inc.