Skip to contentSkip to conversation

rdma: delete the useless casting value returned

PATCH In review Wang Qing 2 participants 2 messages Mar 12, 2021 InfiniBand

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

PATCH 1/1 rdma: delete the useless casting value returned

Fix the following coccicheck warning:
WARNING: casting value returned by memory allocation function is useless.

---
 include/rdma/ib_verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/ib_verbs.h +1 -1
index ca28fca..f4d24d8
@@ -2259,7 +2259,7 @@ struct iw_cm_conn_param;
 				      struct ib_struct)))
 
 #define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp)                         \
-	((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
+	kzalloc(ib_dev->ops.size_##ib_type, gfp)
 
 #define rdma_zalloc_drv_obj(ib_dev, ib_type)                                   \
 	rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 2 lines · Wang Qing

Fix the following coccicheck warning:
WARNING: casting value returned by memory allocation function is useless.

This warning is wrong in this specific case.

The #define is creating a helper function that enforces strict type safety on the user

So eg,

  struct bar *obj = rdma_zalloc_drv_obj(ibdev, ib_ah);

Will fail to compile because 'obj' is not the required ib_ah type

Jason