Blob Blame History Raw
From: Jason Gunthorpe <jgg@mellanox.com>
Date: Wed, 6 Feb 2019 22:41:47 -0700
Subject: RDMA/device: Check that the rename is nop under the lock
Patch-mainline: v5.1-rc1
Git-commit: e3593b568a68b0e1a434b80fd6eaebfb655e839d
References: bsc#1103992 FATE#326009

Since another rename could be running in parallel it is safer to check
that the name is not changing inside the lock, where we already know the
device name will not change.

Fixes: d21943dd19b5 ("RDMA/core: Implement IB device rename function")
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/infiniband/core/device.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -183,12 +183,14 @@ static struct ib_device *__ib_device_get
 int ib_device_rename(struct ib_device *ibdev, const char *name)
 {
 	struct ib_device *device;
-	int ret = 0;
-
-	if (!strcmp(name, dev_name(&ibdev->dev)))
-		return ret;
+	int ret;
 
 	mutex_lock(&device_mutex);
+	if (!strcmp(name, dev_name(&ibdev->dev))) {
+		ret = 0;
+		goto out;
+	}
+
 	list_for_each_entry(device, &device_list, core_list) {
 		if (!strcmp(name, dev_name(&device->dev))) {
 			ret = -EEXIST;