* [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths
@ 2023-03-29 18:14 Leon Romanovsky
2023-03-29 18:44 ` Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-03-29 18:14 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Leon Romanovsky, Bob Pearson, Dan Carpenter, linux-rdma,
Zhu Yanjun
From: Leon Romanovsky <leonro@nvidia.com>
There is no need to print any debug messages after failure to
allocate memory, because kernel will print OOM dumps anyway.
Together with removal of these messages, remove useless goto jumps.
Fixes: 5bf944f24129 ("RDMA/rxe: Add error messages")
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/all/ea43486f-43dd-4054-b1d5-3a0d202be621@kili.mountain
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/infiniband/sw/rxe/rxe_queue.c | 5 ++---
drivers/infiniband/sw/rxe/rxe_verbs.c | 23 ++++++-----------------
2 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_queue.c b/drivers/infiniband/sw/rxe/rxe_queue.c
index d6dbf5a0058d..9611ee191a46 100644
--- a/drivers/infiniband/sw/rxe/rxe_queue.c
+++ b/drivers/infiniband/sw/rxe/rxe_queue.c
@@ -61,11 +61,11 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
/* num_elem == 0 is allowed, but uninteresting */
if (*num_elem < 0)
- goto err1;
+ return NULL;
q = kzalloc(sizeof(*q), GFP_KERNEL);
if (!q)
- goto err1;
+ return NULL;
q->rxe = rxe;
q->type = type;
@@ -100,7 +100,6 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
err2:
kfree(q);
-err1:
return NULL;
}
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index 090d5bfb1e18..06f071832635 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -1198,11 +1198,8 @@ static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
int err;
mr = kzalloc(sizeof(*mr), GFP_KERNEL);
- if (!mr) {
- err = -ENOMEM;
- rxe_dbg_dev(rxe, "no memory for mr");
- goto err_out;
- }
+ if (!mr)
+ return ERR_PTR(-ENOMEM);
err = rxe_add_to_pool(&rxe->mr_pool, mr);
if (err) {
@@ -1220,7 +1217,6 @@ static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
err_free:
kfree(mr);
-err_out:
rxe_err_pd(pd, "returned err = %d", err);
return ERR_PTR(err);
}
@@ -1235,11 +1231,8 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, u64 start,
int err, cleanup_err;
mr = kzalloc(sizeof(*mr), GFP_KERNEL);
- if (!mr) {
- err = -ENOMEM;
- rxe_dbg_pd(pd, "no memory for mr");
- goto err_out;
- }
+ if (!mr)
+ return ERR_PTR(-ENOMEM);
err = rxe_add_to_pool(&rxe->mr_pool, mr);
if (err) {
@@ -1266,7 +1259,6 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, u64 start,
rxe_err_mr(mr, "cleanup failed, err = %d", cleanup_err);
err_free:
kfree(mr);
-err_out:
rxe_err_pd(pd, "returned err = %d", err);
return ERR_PTR(err);
}
@@ -1287,11 +1279,8 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
}
mr = kzalloc(sizeof(*mr), GFP_KERNEL);
- if (!mr) {
- err = -ENOMEM;
- rxe_dbg_mr(mr, "no memory for mr");
- goto err_out;
- }
+ if (!mr)
+ return ERR_PTR(-ENOMEM);
err = rxe_add_to_pool(&rxe->mr_pool, mr);
if (err) {
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths
2023-03-29 18:14 [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths Leon Romanovsky
@ 2023-03-29 18:44 ` Dan Carpenter
2023-03-29 19:18 ` Leon Romanovsky
2023-03-29 19:57 ` Bob Pearson
2023-03-30 6:56 ` Leon Romanovsky
2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2023-03-29 18:44 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Jason Gunthorpe, Leon Romanovsky, Bob Pearson, linux-rdma,
Zhu Yanjun
On Wed, Mar 29, 2023 at 09:14:01PM +0300, Leon Romanovsky wrote:
> @@ -1287,11 +1279,8 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
> }
>
> mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> - if (!mr) {
> - err = -ENOMEM;
> - rxe_dbg_mr(mr, "no memory for mr");
> - goto err_out;
> - }
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
>
> err = rxe_add_to_pool(&rxe->mr_pool, mr);
> if (err) {
^^^^^^^^^^
If the rxe_add_to_pool() fails then it calls:
rxe_dbg_mr(mr, "unable to create mr, err = %d", err);
^^
"rm" is zeroed mem and not useful at this point. Possibly in a later
patch though.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths
2023-03-29 18:44 ` Dan Carpenter
@ 2023-03-29 19:18 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-03-29 19:18 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Jason Gunthorpe, Bob Pearson, linux-rdma, Zhu Yanjun
On Wed, Mar 29, 2023 at 09:44:09PM +0300, Dan Carpenter wrote:
> On Wed, Mar 29, 2023 at 09:14:01PM +0300, Leon Romanovsky wrote:
> > @@ -1287,11 +1279,8 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
> > }
> >
> > mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> > - if (!mr) {
> > - err = -ENOMEM;
> > - rxe_dbg_mr(mr, "no memory for mr");
> > - goto err_out;
> > - }
> > + if (!mr)
> > + return ERR_PTR(-ENOMEM);
> >
> > err = rxe_add_to_pool(&rxe->mr_pool, mr);
> > if (err) {
> ^^^^^^^^^^
> If the rxe_add_to_pool() fails then it calls:
>
> rxe_dbg_mr(mr, "unable to create mr, err = %d", err);
> ^^
>
> "rm" is zeroed mem and not useful at this point. Possibly in a later
> patch though.
I will delete that line when will apply the patch.
Thanks
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths
2023-03-29 18:14 [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths Leon Romanovsky
2023-03-29 18:44 ` Dan Carpenter
@ 2023-03-29 19:57 ` Bob Pearson
2023-03-30 6:56 ` Leon Romanovsky
2 siblings, 0 replies; 5+ messages in thread
From: Bob Pearson @ 2023-03-29 19:57 UTC (permalink / raw)
To: Leon Romanovsky, Jason Gunthorpe
Cc: Leon Romanovsky, Dan Carpenter, linux-rdma, Zhu Yanjun
On 3/29/23 13:14, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> There is no need to print any debug messages after failure to
> allocate memory, because kernel will print OOM dumps anyway.
>
> Together with removal of these messages, remove useless goto jumps.
>
> Fixes: 5bf944f24129 ("RDMA/rxe: Add error messages")
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/all/ea43486f-43dd-4054-b1d5-3a0d202be621@kili.mountain
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> drivers/infiniband/sw/rxe/rxe_queue.c | 5 ++---
> drivers/infiniband/sw/rxe/rxe_verbs.c | 23 ++++++-----------------
> 2 files changed, 8 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_queue.c b/drivers/infiniband/sw/rxe/rxe_queue.c
> index d6dbf5a0058d..9611ee191a46 100644
> --- a/drivers/infiniband/sw/rxe/rxe_queue.c
> +++ b/drivers/infiniband/sw/rxe/rxe_queue.c
> @@ -61,11 +61,11 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
>
> /* num_elem == 0 is allowed, but uninteresting */
> if (*num_elem < 0)
> - goto err1;
> + return NULL;
>
> q = kzalloc(sizeof(*q), GFP_KERNEL);
> if (!q)
> - goto err1;
> + return NULL;
>
> q->rxe = rxe;
> q->type = type;
> @@ -100,7 +100,6 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
>
> err2:
> kfree(q);
> -err1:
> return NULL;
> }
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
> index 090d5bfb1e18..06f071832635 100644
> --- a/drivers/infiniband/sw/rxe/rxe_verbs.c
> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
> @@ -1198,11 +1198,8 @@ static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
> int err;
>
> mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> - if (!mr) {
> - err = -ENOMEM;
> - rxe_dbg_dev(rxe, "no memory for mr");
> - goto err_out;
> - }
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
>
> err = rxe_add_to_pool(&rxe->mr_pool, mr);
> if (err) {
> @@ -1220,7 +1217,6 @@ static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
>
> err_free:
> kfree(mr);
> -err_out:
> rxe_err_pd(pd, "returned err = %d", err);
> return ERR_PTR(err);
> }
> @@ -1235,11 +1231,8 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, u64 start,
> int err, cleanup_err;
>
> mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> - if (!mr) {
> - err = -ENOMEM;
> - rxe_dbg_pd(pd, "no memory for mr");
> - goto err_out;
> - }
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
>
> err = rxe_add_to_pool(&rxe->mr_pool, mr);
> if (err) {
> @@ -1266,7 +1259,6 @@ static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd, u64 start,
> rxe_err_mr(mr, "cleanup failed, err = %d", cleanup_err);
> err_free:
> kfree(mr);
> -err_out:
> rxe_err_pd(pd, "returned err = %d", err);
> return ERR_PTR(err);
> }
> @@ -1287,11 +1279,8 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
> }
>
> mr = kzalloc(sizeof(*mr), GFP_KERNEL);
> - if (!mr) {
> - err = -ENOMEM;
> - rxe_dbg_mr(mr, "no memory for mr");
> - goto err_out;
> - }
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
>
> err = rxe_add_to_pool(&rxe->mr_pool, mr);
> if (err) {
These are all fine. Thanks!
Reviewed-by:- Bob Pearson <rpearsonhpe@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths
2023-03-29 18:14 [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths Leon Romanovsky
2023-03-29 18:44 ` Dan Carpenter
2023-03-29 19:57 ` Bob Pearson
@ 2023-03-30 6:56 ` Leon Romanovsky
2 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2023-03-30 6:56 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky
Cc: Bob Pearson, Dan Carpenter, linux-rdma, Zhu Yanjun,
Leon Romanovsky
On Wed, 29 Mar 2023 21:14:01 +0300, Leon Romanovsky wrote:
> There is no need to print any debug messages after failure to
> allocate memory, because kernel will print OOM dumps anyway.
>
> Together with removal of these messages, remove useless goto jumps.
>
>
Applied, thanks!
[1/1] RDMA/rxe: Clean kzalloc failure paths
https://git.kernel.org/rdma/rdma/c/b6ba68555d75fd
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-30 6:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-29 18:14 [PATCH rdma-next] RDMA/rxe: Clean kzalloc failure paths Leon Romanovsky
2023-03-29 18:44 ` Dan Carpenter
2023-03-29 19:18 ` Leon Romanovsky
2023-03-29 19:57 ` Bob Pearson
2023-03-30 6:56 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox