All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries
@ 2022-08-01  7:38 William Kucharski
  2022-08-01  7:51 ` Zhu Yanjun
  2022-08-01 19:12 ` Bob Pearson
  0 siblings, 2 replies; 3+ messages in thread
From: William Kucharski @ 2022-08-01  7:38 UTC (permalink / raw)
  To: Zhu Yanjun, Jason Gunthorpe, Leon Romanovsky, rpearsonhpe,
	linux-rdma, linux-kernel
  Cc: William Kucharski

The current code will report an error if xa_alloc_cyclic() returns
non-zero, but it will return 1 if it wrapped indices before successfully
allocating an entry.

An error should only be reported if the call actually failed (denoted by
a return value < 0.)

Fixes: 3225717f6dfa2 ("RDMA/rxe: Replace red-black trees by xarrays")
Signed-off-by: William Kucharski <william.kucharski@oracle.com>
---
 drivers/infiniband/sw/rxe/rxe_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
index 19b14826385b..e9f3bbd8d605 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.c
+++ b/drivers/infiniband/sw/rxe/rxe_pool.c
@@ -139,7 +139,7 @@ void *rxe_alloc(struct rxe_pool *pool)
 
 	err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
 			      &pool->next, GFP_KERNEL);
-	if (err)
+	if (err < 0)
 		goto err_free;
 
 	return obj;
@@ -167,7 +167,7 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem)
 
 	err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
 			      &pool->next, GFP_KERNEL);
-	if (err)
+	if (err < 0)
 		goto err_cnt;
 
 	return 0;
-- 
2.37.1


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

* Re: [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries
  2022-08-01  7:38 [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries William Kucharski
@ 2022-08-01  7:51 ` Zhu Yanjun
  2022-08-01 19:12 ` Bob Pearson
  1 sibling, 0 replies; 3+ messages in thread
From: Zhu Yanjun @ 2022-08-01  7:51 UTC (permalink / raw)
  To: William Kucharski
  Cc: Jason Gunthorpe, Leon Romanovsky, Bob Pearson, RDMA mailing list, LKML

On Mon, Aug 1, 2022 at 3:39 PM William Kucharski
<william.kucharski@oracle.com> wrote:
>
> The current code will report an error if xa_alloc_cyclic() returns
> non-zero, but it will return 1 if it wrapped indices before successfully
> allocating an entry.
>
> An error should only be reported if the call actually failed (denoted by
> a return value < 0.)
>
> Fixes: 3225717f6dfa2 ("RDMA/rxe: Replace red-black trees by xarrays")
> Signed-off-by: William Kucharski <william.kucharski@oracle.com>

Please check commit in
https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git

commit 1a685940e6200e9def6e34bbaa19dd31dc5aeaf8
Author: Dongliang Mu <mudongliangabcd@gmail.com>
Date:   Thu Jun 9 15:06:56 2022 +0800

    RDMA/rxe: fix xa_alloc_cycle() error return value check again

    Currently rxe_alloc checks ret to indicate error, but 1 is also a valid
    return and just indicates that the allocation succeeded with a wrap.

    Fix this by modifying the check to be < 0.

    Link: https://lore.kernel.org/r/20220609070656.1446121-1-dzm91@hust.edu.cn
    Fixes: 3225717f6dfa ("RDMA/rxe: Replace red-black trees by xarrays")
    Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
    Reviewed-by: Bob Pearson <rpearsonhpe@gmail.com>
    Signed-off-by: Leon Romanovsky <leon@kernel.org>

Thanks and Regards,
Zhu Yanjun

> ---
>  drivers/infiniband/sw/rxe/rxe_pool.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
> index 19b14826385b..e9f3bbd8d605 100644
> --- a/drivers/infiniband/sw/rxe/rxe_pool.c
> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
> @@ -139,7 +139,7 @@ void *rxe_alloc(struct rxe_pool *pool)
>
>         err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
>                               &pool->next, GFP_KERNEL);
> -       if (err)
> +       if (err < 0)
>                 goto err_free;
>
>         return obj;
> @@ -167,7 +167,7 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem)
>
>         err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
>                               &pool->next, GFP_KERNEL);
> -       if (err)
> +       if (err < 0)
>                 goto err_cnt;
>
>         return 0;
> --
> 2.37.1
>

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

* Re: [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries
  2022-08-01  7:38 [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries William Kucharski
  2022-08-01  7:51 ` Zhu Yanjun
@ 2022-08-01 19:12 ` Bob Pearson
  1 sibling, 0 replies; 3+ messages in thread
From: Bob Pearson @ 2022-08-01 19:12 UTC (permalink / raw)
  To: William Kucharski, Zhu Yanjun, Jason Gunthorpe, Leon Romanovsky,
	linux-rdma, linux-kernel

On 8/1/22 02:38, William Kucharski wrote:
> The current code will report an error if xa_alloc_cyclic() returns
> non-zero, but it will return 1 if it wrapped indices before successfully
> allocating an entry.
> 
> An error should only be reported if the call actually failed (denoted by
> a return value < 0.)
> 
> Fixes: 3225717f6dfa2 ("RDMA/rxe: Replace red-black trees by xarrays")
> Signed-off-by: William Kucharski <william.kucharski@oracle.com>
> ---
>  drivers/infiniband/sw/rxe/rxe_pool.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
> index 19b14826385b..e9f3bbd8d605 100644
> --- a/drivers/infiniband/sw/rxe/rxe_pool.c
> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
> @@ -139,7 +139,7 @@ void *rxe_alloc(struct rxe_pool *pool)
>  
>  	err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
>  			      &pool->next, GFP_KERNEL);
> -	if (err)
> +	if (err < 0)
>  		goto err_free;
>  
>  	return obj;
> @@ -167,7 +167,7 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem)
>  
>  	err = xa_alloc_cyclic(&pool->xa, &elem->index, elem, pool->limit,
>  			      &pool->next, GFP_KERNEL);
> -	if (err)
> +	if (err < 0)
>  		goto err_cnt;
>  
>  	return 0;

We fixed this a while back but not sure what happened. In any case this is absolutely correct.
You can add

Reviewed-by: Bob Pearson <rpearsonhpe@gmail.com>

Bob

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

end of thread, other threads:[~2022-08-01 19:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01  7:38 [PATCH] RDMA/rxe: Correct error handling in routines allocating xarray entries William Kucharski
2022-08-01  7:51 ` Zhu Yanjun
2022-08-01 19:12 ` Bob Pearson

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.