diff mbox series

[for-next,1/3] RDMA/core: Check for error instead of success in alloc MR function

Message ID 20200706120343.10816-2-galpress@amazon.com (mailing list archive)
State Mainlined
Commit c5f42b21051517a2070a67d21be8e423d5fdf0d9
Delegated to: Jason Gunthorpe
Headers show
Series Allocate MR cleanups | expand

Commit Message

Gal Pressman July 6, 2020, 12:03 p.m. UTC
The common kernel pattern is to check for error, not success.
Flip the if statement accordingly and keep the main flow unindented.

Signed-off-by: Gal Pressman <galpress@amazon.com>
---
 drivers/infiniband/core/verbs.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Leon Romanovsky July 6, 2020, 12:32 p.m. UTC | #1
On Mon, Jul 06, 2020 at 03:03:41PM +0300, Gal Pressman wrote:
> The common kernel pattern is to check for error, not success.
> Flip the if statement accordingly and keep the main flow unindented.
>
> Signed-off-by: Gal Pressman <galpress@amazon.com>
> ---
>  drivers/infiniband/core/verbs.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
diff mbox series

Patch

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 7232e6ec2e91..759de1372c59 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -2133,18 +2133,19 @@  struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type,
 	}
 
 	mr = pd->device->ops.alloc_mr(pd, mr_type, max_num_sg, udata);
-	if (!IS_ERR(mr)) {
-		mr->device  = pd->device;
-		mr->pd      = pd;
-		mr->dm      = NULL;
-		mr->uobject = NULL;
-		atomic_inc(&pd->usecnt);
-		mr->need_inval = false;
-		mr->res.type = RDMA_RESTRACK_MR;
-		rdma_restrack_kadd(&mr->res);
-		mr->type = mr_type;
-		mr->sig_attrs = NULL;
-	}
+	if (IS_ERR(mr))
+		goto out;
+
+	mr->device  = pd->device;
+	mr->pd      = pd;
+	mr->dm      = NULL;
+	mr->uobject = NULL;
+	atomic_inc(&pd->usecnt);
+	mr->need_inval = false;
+	mr->res.type = RDMA_RESTRACK_MR;
+	rdma_restrack_kadd(&mr->res);
+	mr->type = mr_type;
+	mr->sig_attrs = NULL;
 
 out:
 	trace_mr_alloc(pd, mr_type, max_num_sg, mr);