Use kmalloc_array() instead of kmalloc()
Subsystems (2)
PATCH v2 1/1 Use kmalloc_array() instead of kmalloc()
Refactor to new API, for cases with dynamic size calculations inside kmalloc(). Such calculations were found using grep in the sources. The patch compiles properly with multi_v7_defconfig and multi_v5_defconfig and generates object files for the following driver files.
---
Changelog:
v1:https://lore.kernel.org/all/[email protected]/ -refactor code and run checkpatch.
-use sizeof(*ptr) not sizeof(void*).
-add RFT and the how the issue was found.
drivers/clk/at91/sam9x7.c +3 -3
@@ -754,9 +754,9 @@ static void __init sam9x7_pmc_setup(struct device_node *np)if (!sam9x7_pmc)return ; - clk_mux_buffer =kmalloc (sizeof (void *) * - (ARRAY_SIZE (sam9x7_gck)), -GFP_KERNEL ); + clk_mux_buffer =kmalloc_array (ARRAY_SIZE (sam9x7_gck), +sizeof (*clk_mux_buffer), +GFP_KERNEL );if (!clk_mux_buffer) goto err_free;
drivers/clk/at91/sama7d65.c +3 -3
@@ -1127,9 +1127,9 @@ static void __init sama7d65_pmc_setup(struct device_node *np)if (!sama7d65_pmc)return ; - alloc_mem =kmalloc (sizeof (void *) * - (ARRAY_SIZE (sama7d65_mckx) +ARRAY_SIZE (sama7d65_gck)), -GFP_KERNEL ); + alloc_mem =kmalloc_array (ARRAY_SIZE (sama7d65_mckx) +ARRAY_SIZE (sama7d65_gck), +sizeof (*alloc_mem), +GFP_KERNEL );if (!alloc_mem) goto err_free;
drivers/clk/at91/sama7g5.c +3 -3
@@ -1004,9 +1004,9 @@ static void __init sama7g5_pmc_setup(struct device_node *np)if (!sama7g5_pmc)return ; - alloc_mem =kmalloc (sizeof (void *) * - (ARRAY_SIZE (sama7g5_mckx) +ARRAY_SIZE (sama7g5_gck)), -GFP_KERNEL ); + alloc_mem =kmalloc_array (ARRAY_SIZE (sama7g5_mckx) +ARRAY_SIZE (sama7g5_gck), +sizeof (*alloc_mem), +GFP_KERNEL );if (!alloc_mem) goto err_free;
Signature · 1 line
2.43.0
Claudiu Beznea
maintainerPlease use "clk: at91: Use kmalloc_array() instead of kmalloc()" in patch title.
Quoted 5 lines · Sidharth Seela
Refactor to new API, for cases with dynamic size calculations inside
kmalloc(). Such calculations were found using grep in the sources. The patch compiles properly withmulti_v7_defconfigandmulti_v5_defconfigand generates object files for the following driver files.
Patch description should answer to "what?" are you doing and "why?" are you doing it. Please specify also why are you doing this change.
The rest looks good to me.
I tested it and saw no issues.
Thank you,
Claudiu