Skip to contentSkip to conversation

IB/hfi1: Adjust fd->entry_to_rb allocation type

PATCH Applied Kees Cook 2 participants 2 messages Apr 26, 2025 – Apr 27, 2025

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 IB/hfi1: Adjust fd->entry_to_rb 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 "struct tid_rb_node **", but the return type will be "struct rb_node **". These are the same allocation size (pointer size), but the types do not match. Adjust the allocation type to match the assignment.

---
Cc: Dennis Dalessandro <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: <[email protected]>

---
 drivers/infiniband/hw/hfi1/user_exp_rcv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/user_exp_rcv.c +1 -1
index cf2d29098406..62b4f16dab27 100644
@@ -53,7 +53,7 @@ int hfi1_user_exp_rcv_init(struct hfi1_filedata *fd,
 	int ret = 0;
 
 	fd->entry_to_rb = kcalloc(uctxt->expected_count,
-				  sizeof(struct rb_node *),
+				  sizeof(*fd->entry_to_rb),
 				  GFP_KERNEL);
 	if (!fd->entry_to_rb)
 		return -ENOMEM;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 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 "struct tid_rb_node **", but the return type will be "struct rb_node **". These are the same allocation size (pointer size), but the types do not match. Adjust the allocation type to match the assignment.

[...]

Applied, thanks!

[1/1] IB/hfi1: Adjust fd->entry_to_rb allocation type

      https://git.kernel.org/rdma/rdma/c/3db60cf9b7da4a

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>