ptp: ocp: Add const to bp->attr_group allocation type
PATCH 1/1 ptp: ocp: Add const to bp->attr_group allocation type
In preparation for making the 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.)
The assigned type is "const struct attribute_group **", but the returned type, while technically matching, will be not const qualified. As there is no general way to safely add const qualifiers, adjust the allocation type to match the assignment.
---
Cc: Jonathan Lemon <[email protected]>
Cc: Vadim Fedorenko <[email protected]>
Cc: Richard Cochran <[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/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -2372,7 +2372,7 @@ ptp_ocp_attr_group_add(struct ptp_ocp *bp,if (attr_tbl[i].cap & bp->fw_cap) count++; - bp->attr_group =kcalloc (count +1 ,sizeof (struct attribute_group *), + bp->attr_group =kcalloc (count +1 ,sizeof (*bp->attr_group),GFP_KERNEL );if (!bp->attr_group)return -ENOMEM ;
Signature · 1 line
2.34.1
Quoted 30 lines · Kees Cook
In preparation for making the 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.)
The assigned type is "const struct
attribute_group**", but the returned type, while technically matching, will be not const qualified. As there is no general way to safely add const qualifiers, adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>---
Cc: Jonathan Lemon <[email protected]>
Cc: Vadim Fedorenko <[email protected]>
Cc: Richard Cochran <[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/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c ptp_ocp_attr_group_add(struct ptp_ocp *bp, · line 2378
Quoted 8 lines
drivers/ptp/ptp_ocp.c +1
-1@@ -2372,7 +2372,7 @@ ptp_ocp_attr_group_add(struct ptp_ocp *bp,if (attr_tbl[i].cap & bp->fw_cap) count++; - bp->attr_group =kcalloc (count +1 ,sizeof (struct attribute_group *), + bp->attr_group =kcalloc (count +1 ,sizeof (*bp->attr_group),GFP_KERNEL );if (!bp->attr_group)return -ENOMEM ;
Thanks,
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 11 lines · On Fri, 25 Apr 2025 23:18:59 -0700 you wrote:
In preparation for making the 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.)
The assigned type is "const struct
attribute_group**", but the returned type, while technically matching, will be not const qualified. As there is no general way to safely add const qualifiers, adjust the allocation type to match the assignment.[...]
Here is the summary with links:
- ptp: ocp: Add const to bp->attr_group allocation type
https://git.kernel.org/netdev/net-next/c/5fe6530cd54b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html