* [PATCH v2 rdma-next] RDMA: Use ERR_CAST to return an error-valued pointer
@ 2024-09-06 6:21 Yu Jiaoliang
2024-09-10 12:23 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Yu Jiaoliang @ 2024-09-06 6:21 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky, Mustafa Ismail,
Tatyana Nikolova, Erick Archer, Akiva Goldberger,
Patrisious Haddad, Max Gurtovoy, Or Har-Toov, Rohit Chavan,
Shigeru Yoshida, linux-rdma, linux-kernel
Cc: opensource.kernel
Instead of directly casting and returning an error-valued pointer,
use ERR_CAST to make the error handling more explicit and improve
code clarity.
Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
v2:
- Additional modifications in file /drivers/infiniband/hw/irdma/verbs.c
v1: https://lore.kernel.org/all/20240905110615.GU4026@unreal/
---
drivers/infiniband/core/mad_rmpp.c | 2 +-
drivers/infiniband/core/uverbs_cmd.c | 2 +-
drivers/infiniband/core/verbs.c | 2 +-
drivers/infiniband/hw/irdma/verbs.c | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
index 8af0619a39cd..b4b10e8a6495 100644
--- a/drivers/infiniband/core/mad_rmpp.c
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -158,7 +158,7 @@ static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent,
ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc,
recv_wc->recv_buf.grh, agent->port_num);
if (IS_ERR(ah))
- return (void *) ah;
+ return ERR_CAST(ah);
hdr_len = ib_get_mad_data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
msg = ib_create_send_mad(agent, recv_wc->wc->src_qp,
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 1b3ea71f2c33..35a83825f6ba 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -192,7 +192,7 @@ _ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
fd, attrs);
if (IS_ERR(uobj))
- return (void *)uobj;
+ return ERR_CAST(uobj);
uverbs_uobject_get(uobj);
uobj_put_read(uobj);
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 473ee0831307..77268cce4d31 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -572,7 +572,7 @@ struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
GFP_KERNEL : GFP_ATOMIC);
if (IS_ERR(slave)) {
rdma_unfill_sgid_attr(ah_attr, old_sgid_attr);
- return (void *)slave;
+ return ERR_CAST(slave);
}
ah = _rdma_create_ah(pd, ah_attr, flags, NULL, slave);
rdma_lag_put_ah_roce_slave(slave);
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index 6a107decb704..1ae336800c63 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -3037,7 +3037,7 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len,
if (IS_ERR(region)) {
ibdev_dbg(&iwdev->ibdev,
"VERBS: Failed to create ib_umem region\n");
- return (struct ib_mr *)region;
+ return ERR_CAST(region);
}
if (ib_copy_from_udata(&req, udata, min(sizeof(req), udata->inlen))) {
@@ -3048,7 +3048,7 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len,
iwmr = irdma_alloc_iwmr(region, pd, virt, req.reg_type);
if (IS_ERR(iwmr)) {
ib_umem_release(region);
- return (struct ib_mr *)iwmr;
+ return ERR_CAST(iwmr);
}
switch (req.reg_type) {
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 rdma-next] RDMA: Use ERR_CAST to return an error-valued pointer
2024-09-06 6:21 [PATCH v2 rdma-next] RDMA: Use ERR_CAST to return an error-valued pointer Yu Jiaoliang
@ 2024-09-10 12:23 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2024-09-10 12:23 UTC (permalink / raw)
To: Yu Jiaoliang
Cc: Jason Gunthorpe, Mustafa Ismail, Tatyana Nikolova, Erick Archer,
Akiva Goldberger, Patrisious Haddad, Max Gurtovoy, Or Har-Toov,
Rohit Chavan, Shigeru Yoshida, linux-rdma, linux-kernel,
opensource.kernel
On Fri, Sep 06, 2024 at 02:21:36PM +0800, Yu Jiaoliang wrote:
> Instead of directly casting and returning an error-valued pointer,
> use ERR_CAST to make the error handling more explicit and improve
> code clarity.
>
> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
> ---
> v2:
> - Additional modifications in file /drivers/infiniband/hw/irdma/verbs.c
> v1: https://lore.kernel.org/all/20240905110615.GU4026@unreal/
> ---
> drivers/infiniband/core/mad_rmpp.c | 2 +-
> drivers/infiniband/core/uverbs_cmd.c | 2 +-
> drivers/infiniband/core/verbs.c | 2 +-
> drivers/infiniband/hw/irdma/verbs.c | 4 ++--
> 4 files changed, 5 insertions(+), 5 deletions(-)
It is still incomplete.
Something like that will give you a better result:
➜ kernel git:(wip/leon-for-next) git grep "return (" drivers/infiniband/ | grep "\*"
Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-10 12:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 6:21 [PATCH v2 rdma-next] RDMA: Use ERR_CAST to return an error-valued pointer Yu Jiaoliang
2024-09-10 12:23 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox