All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rdma: delete the useless casting value returned
@ 2021-03-12  2:19 Wang Qing
  2021-03-12 13:10 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Qing @ 2021-03-12  2:19 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe, linux-rdma, linux-kernel; +Cc: Wang Qing

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

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 include/rdma/ib_verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index ca28fca..f4d24d8
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -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)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rdma: delete the useless casting value returned
  2021-03-12  2:19 [PATCH] rdma: delete the useless casting value returned Wang Qing
@ 2021-03-12 13:10 ` Jason Gunthorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2021-03-12 13:10 UTC (permalink / raw)
  To: Wang Qing; +Cc: Doug Ledford, linux-rdma, linux-kernel

On Fri, Mar 12, 2021 at 10:19:30AM +0800, Wang Qing wrote:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-12 13:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12  2:19 [PATCH] rdma: delete the useless casting value returned Wang Qing
2021-03-12 13:10 ` Jason Gunthorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.