diff mbox series

[v1] RDMA/sw/rdmavt/mr: Convert to use ERR_CAST()

Message ID 20240828082720.33231-1-shenlichuan@vivo.com (mailing list archive)
State Accepted
Headers show
Series [v1] RDMA/sw/rdmavt/mr: Convert to use ERR_CAST() | expand

Commit Message

Shen Lichuan Aug. 28, 2024, 8:27 a.m. UTC
As opposed to open-code, using the ERR_CAST macro clearly indicates that 
this is a pointer to an error value and a type conversion was performed.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
---
 drivers/infiniband/sw/rdmavt/mr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Dennis Dalessandro Aug. 28, 2024, 4:06 p.m. UTC | #1
On 8/28/24 4:27 AM, Shen Lichuan wrote:
> As opposed to open-code, using the ERR_CAST macro clearly indicates that 
> this is a pointer to an error value and a type conversion was performed.
> 
> Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
> ---
>  drivers/infiniband/sw/rdmavt/mr.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c
> index 7a9afd5231d5..5ed5cfc2b280 100644
> --- a/drivers/infiniband/sw/rdmavt/mr.c
> +++ b/drivers/infiniband/sw/rdmavt/mr.c
> @@ -348,13 +348,13 @@ struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
>  
>  	umem = ib_umem_get(pd->device, start, length, mr_access_flags);
>  	if (IS_ERR(umem))
> -		return (void *)umem;
> +		return ERR_CAST(umem);
>  
>  	n = ib_umem_num_pages(umem);
>  
>  	mr = __rvt_alloc_mr(n, pd);
>  	if (IS_ERR(mr)) {
> -		ret = (struct ib_mr *)mr;
> +		ret = ERR_CAST(mr);
>  		goto bail_umem;
>  	}
>  
> @@ -542,7 +542,7 @@ struct ib_mr *rvt_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
>  
>  	mr = __rvt_alloc_mr(max_num_sg, pd);
>  	if (IS_ERR(mr))
> -		return (struct ib_mr *)mr;
> +		return ERR_CAST(mr);
>  
>  	return &mr->ibmr;
>  }

I don't think this is really necessary. You are not making the code more
readable. It doesn't simplify things. So I'm not going to Ack it, but I won't
Nak either.

-Denny
Leon Romanovsky Aug. 29, 2024, 10:17 a.m. UTC | #2
On Wed, Aug 28, 2024 at 12:06:17PM -0400, Dennis Dalessandro wrote:
> On 8/28/24 4:27 AM, Shen Lichuan wrote:
> > As opposed to open-code, using the ERR_CAST macro clearly indicates that 
> > this is a pointer to an error value and a type conversion was performed.
> > 
> > Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
> > ---
> >  drivers/infiniband/sw/rdmavt/mr.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c
> > index 7a9afd5231d5..5ed5cfc2b280 100644
> > --- a/drivers/infiniband/sw/rdmavt/mr.c
> > +++ b/drivers/infiniband/sw/rdmavt/mr.c
> > @@ -348,13 +348,13 @@ struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
> >  
> >  	umem = ib_umem_get(pd->device, start, length, mr_access_flags);
> >  	if (IS_ERR(umem))
> > -		return (void *)umem;
> > +		return ERR_CAST(umem);
> >  
> >  	n = ib_umem_num_pages(umem);
> >  
> >  	mr = __rvt_alloc_mr(n, pd);
> >  	if (IS_ERR(mr)) {
> > -		ret = (struct ib_mr *)mr;
> > +		ret = ERR_CAST(mr);
> >  		goto bail_umem;
> >  	}
> >  
> > @@ -542,7 +542,7 @@ struct ib_mr *rvt_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
> >  
> >  	mr = __rvt_alloc_mr(max_num_sg, pd);
> >  	if (IS_ERR(mr))
> > -		return (struct ib_mr *)mr;
> > +		return ERR_CAST(mr);
> >  
> >  	return &mr->ibmr;
> >  }
> 
> I don't think this is really necessary. You are not making the code more
> readable. It doesn't simplify things. So I'm not going to Ack it, but I won't
> Nak either.

I will take it because ERR_CAST is slightly better way to return error pointers.

Thanks

> 
> -Denny
Leon Romanovsky Aug. 29, 2024, 10:19 a.m. UTC | #3
On Wed, 28 Aug 2024 16:27:20 +0800, Shen Lichuan wrote:
> As opposed to open-code, using the ERR_CAST macro clearly indicates that
> this is a pointer to an error value and a type conversion was performed.
> 
> 

Applied, thanks!

[1/1] RDMA/sw/rdmavt/mr: Convert to use ERR_CAST()
      https://git.kernel.org/rdma/rdma/c/8f1f60b21b9603

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c
index 7a9afd5231d5..5ed5cfc2b280 100644
--- a/drivers/infiniband/sw/rdmavt/mr.c
+++ b/drivers/infiniband/sw/rdmavt/mr.c
@@ -348,13 +348,13 @@  struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 
 	umem = ib_umem_get(pd->device, start, length, mr_access_flags);
 	if (IS_ERR(umem))
-		return (void *)umem;
+		return ERR_CAST(umem);
 
 	n = ib_umem_num_pages(umem);
 
 	mr = __rvt_alloc_mr(n, pd);
 	if (IS_ERR(mr)) {
-		ret = (struct ib_mr *)mr;
+		ret = ERR_CAST(mr);
 		goto bail_umem;
 	}
 
@@ -542,7 +542,7 @@  struct ib_mr *rvt_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
 
 	mr = __rvt_alloc_mr(max_num_sg, pd);
 	if (IS_ERR(mr))
-		return (struct ib_mr *)mr;
+		return ERR_CAST(mr);
 
 	return &mr->ibmr;
 }