octeontx2-af: Allocate ikpu2 with ARRAY_SIZE()
PATCH 1/1 octeontx2-af: Allocate ikpu2 with ARRAY_SIZE()
From: Kees Cook <[email protected]>
In preparation for making the devm_kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This is allocating room for a copy of ikpu_action_entries, which is an array of struct npc_kpu_profile_action, but it asked for a single object the size of the whole array, which would make the allocation type a pointer to the array rather than the "struct npc_kpu_profile_action *" being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting allocation size is the same.
Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.o
---
Cc: Sunil Goutham <[email protected]>
Cc: Ratheesh Kannoth <[email protected]>
Cc: Geetha sowjanya <[email protected]>
Cc: Subbaraya Sundeep <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: <[email protected]>
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +3 -2
@@ -1959,8 +1959,9 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu, fw = rvu->kpu_fwdata;/* Binary blob contains ikpu actions entries at start of data[0] */ - profile->ikpu2 =devm_kcalloc (rvu->dev,1 , -sizeof (ikpu_action_entries), + profile->ikpu2 =devm_kcalloc (rvu->dev, +ARRAY_SIZE (ikpu_action_entries), +sizeof (*profile->ikpu2),GFP_KERNEL );if (!profile->ikpu2)return -ENOMEM ;
Signature · 1 line
2.34.1
Quoted 18 lines · Kees Cook
From: Kees Cook <[email protected]>
In preparation for making the
devm_kmallocfamily of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)This is allocating room for a copy of
ikpu_action_entries, which is an array of structnpc_kpu_profile_action, but it asked for a single object the size of the whole array, which would make the allocation type a pointer to the array rather than the "structnpc_kpu_profile_action*" being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting allocation size is the same.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static int npc_apply_custom_kpu_from_fs(struct rvu *rvu, · line 1965
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +3
-2@@ -1959,8 +1959,9 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu, fw = rvu->kpu_fwdata;/* Binary blob contains ikpu actions entries at start of data[0] */ - profile->ikpu2 =devm_kcalloc (rvu->dev,1 , -sizeof (ikpu_action_entries), + profile->ikpu2 =devm_kcalloc (rvu->dev, +ARRAY_SIZE (ikpu_action_entries), +sizeof (*profile->ikpu2),GFP_KERNEL );
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 17 Sep 2026 14:14:10 -0700 you wrote:
From: Kees Cook <[email protected]>
In preparation for making the
devm_kmallocfamily of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)[...]
Here is the summary with links:
- [net-next] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE()
https://git.kernel.org/netdev/net-next/c/bfc9df9e40c9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html