Skip to contentSkip to conversation

RDMA/mlx5: check reg_create() create for errors

PATCH Applied Dan Carpenter 3 participants 3 messages Feb 6, 2023 – Feb 7, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/mlx5: check reg_create() create for errors

The reg_create() can fail. Check for errors before dereferencing it.

Fixes dd1b913fb0d0 ("RDMA/mlx5: Cache all user cacheable mkeys on dereg MR flow")
---
 drivers/infiniband/hw/mlx5/mr.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/infiniband/hw/mlx5/mr.c +2 -0
index c396b942d0c8..2feab0818a76 100644
@@ -1164,6 +1164,8 @@ static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd,
 		mutex_lock(&dev->slow_path_mutex);
 		mr = reg_create(pd, umem, iova, access_flags, page_size, false);
 		mutex_unlock(&dev->slow_path_mutex);
+		if (IS_ERR(mr))
+			return mr;
 		mr->mmkey.rb_key = rb_key;
 		return mr;
 	}
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines

-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Monday, February 6, 2023 8:11 PM
To: Michael Guralnik <[email protected]>; Leon Romanovsky <[email protected]>
Cc: Jason Gunthorpe <[email protected]>; [email protected]; kernel- [email protected]
Subject: [PATCH] RDMA/mlx5: check reg_create() create for errors

The reg_create() can fail. Check for errors before dereferencing it.

Fixes dd1b913fb0d0 ("RDMA/mlx5: Cache all user cacheable mkeys on dereg

MR flow")

---
 drivers/infiniband/hw/mlx5/mr.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/infiniband/hw/mlx5/mr.c index c396b942d0c8..2feab0818a76 100644

drivers/infiniband/hw/mlx5/mr.c static struct mlx5_ib_mr · line 1170

Quoted 7 lines
drivers/infiniband/hw/mlx5/mr.c +2 -0
@@ -1164,6 +1164,8 @@ static struct mlx5_ib_mr
 *alloc_cacheable_mr(struct ib_pd *pd,
 		mutex_lock(&dev->slow_path_mutex);
 		mr = reg_create(pd, umem, iova, access_flags, page_size,
 false);
 		mutex_unlock(&dev->slow_path_mutex);
+		if (IS_ERR(mr))
+			return mr;

Looks good

Quoted 5 lines
drivers/infiniband/hw/mlx5/mr.c +0 -0
 		mr->mmkey.rb_key = rb_key;
drivers/infiniband/hw/mlx5/mr.c +0 -1
 		return mr;
 	}
--

2.35.1