perf/x86/amd/uncore: Use kcalloc*() instead of kzalloc*()
Subsystems (2)
PATCH 1/1 perf/x86/amd/uncore: Use kcalloc*() instead of kzalloc*()
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
So, use the purpose specific kcalloc*() function instead of the argument size * count in the kzalloc*() function.
--- arch/x86/events/amd/uncore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/amd/uncore.c +3 -3
@@ -479,8 +479,8 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu) goto fail; curr->cpu = cpu; - curr->events =kzalloc_node (sizeof (*curr->events) * - pmu->num_counters, + curr->events =kcalloc_node (pmu->num_counters, +sizeof (*curr->events),GFP_KERNEL , node);if (!curr->events) {kfree (curr);
@@ -928,7 +928,7 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu) 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 ;
--
2.25.1
Quoted 8 lines · Erick Archer
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
Quoted 7 lines
So, use the purpose specific kcalloc*() function instead of the argument size * count in the kzalloc*() function.
Signed-off-by Erick Archer <[email protected]>
Thanks!
Signature · 1 line
Gustavo
Quoted 32 lines
--- arch/x86/events/amd/uncore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/x86/events/amd/uncore.c +3
-4@@ -479,8 +479,8 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu) goto fail; curr->cpu = cpu; - curr->events =kzalloc_node (sizeof (*curr->events) * - pmu->num_counters, + curr->events =kcalloc_node (pmu->num_counters, +sizeof (*curr->events),GFP_KERNEL , node);if (!curr->events) {kfree (curr);@@ -928,7 +928,7 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu) 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 ; --2.25.1