* [PATCH] perf/x86/amd/uncore: use kcalloc() instead of multiplication
@ 2025-09-13 6:35 Joey Pabalinas
2025-09-28 6:45 ` Mi, Dapeng
2025-10-16 20:52 ` [PATCH RESEND] " Joey Pabalinas
0 siblings, 2 replies; 3+ messages in thread
From: Joey Pabalinas @ 2025-09-13 6:35 UTC (permalink / raw)
To: linux-kernel
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Liang, Kan, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
linux-perf-users, Joey Pabalinas
[-- Attachment #1: Type: text/plain, Size: 1055 bytes --]
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf/x86/amd/uncore: use kcalloc() instead of multiplication
2025-09-13 6:35 [PATCH] perf/x86/amd/uncore: use kcalloc() instead of multiplication Joey Pabalinas
@ 2025-09-28 6:45 ` Mi, Dapeng
2025-10-16 20:52 ` [PATCH RESEND] " Joey Pabalinas
1 sibling, 0 replies; 3+ messages in thread
From: Mi, Dapeng @ 2025-09-28 6:45 UTC (permalink / raw)
To: Joey Pabalinas, linux-kernel
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Liang, Kan, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
linux-perf-users
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH RESEND] perf/x86/amd/uncore: use kcalloc() instead of multiplication
2025-09-13 6:35 [PATCH] perf/x86/amd/uncore: use kcalloc() instead of multiplication Joey Pabalinas
2025-09-28 6:45 ` Mi, Dapeng
@ 2025-10-16 20:52 ` Joey Pabalinas
1 sibling, 0 replies; 3+ messages in thread
From: Joey Pabalinas @ 2025-10-16 20:52 UTC (permalink / raw)
To: linux-kernel
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Liang, Kan, Thomas Gleixner,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
linux-perf-users, Mi, Dapeng, Joey Pabalinas
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
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>
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-16 20:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-13 6:35 [PATCH] perf/x86/amd/uncore: use kcalloc() instead of multiplication Joey Pabalinas
2025-09-28 6:45 ` Mi, Dapeng
2025-10-16 20:52 ` [PATCH RESEND] " Joey Pabalinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox