Skip to contentSkip to conversation

md: fix return value of mddev_trylock

PATCH In review Xiao Ni 3 participants 3 messages Jan 27 – Jan 28 MD RAID

lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

PATCH 1/1 md: fix return value of mddev_trylock

A return value of 0 is treaded as successful lock acquisition. In fact, a return value of 1 means getting the lock successfully.

---
 drivers/md/md.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.h +2 -2
index 6985f2829bbd..3bfbee595156 100644
@@ -737,8 +737,8 @@ static inline int mddev_trylock(struct mddev *mddev)
 	int ret;
 
 	ret = mutex_trylock(&mddev->reconfig_mutex);
-	if (!ret && test_bit(MD_DELETED, &mddev->flags)) {
-		ret = -ENODEV;
+	if (ret && test_bit(MD_DELETED, &mddev->flags)) {
+		ret = 0;
 		mutex_unlock(&mddev->reconfig_mutex);
 	}
 	return ret;
Signature · 1 line
2.50.1 (Apple Git-155)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Xiao Ni

A return value of 0 is treaded as successful lock acquisition. In fact, a return value of 1 means getting the lock successfully.

---
  drivers/md/md.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.h +0 -0
index 6985f2829bbd..3bfbee595156 100644

drivers/md/md.h static inline int mddev_trylock(struct mddev *mddev) · line 744

Quoted 10 lines
drivers/md/md.h +2 -2
@@ -737,8 +737,8 @@ static inline int mddev_trylock(struct mddev *mddev)
  	int ret;
 
  	ret = mutex_trylock(&mddev->reconfig_mutex);
-	if (!ret && test_bit(MD_DELETED, &mddev->flags)) {
-		ret = -ENODEV;
+	if (ret && test_bit(MD_DELETED, &mddev->flags)) {
+		ret = 0;
  		mutex_unlock(&mddev->reconfig_mutex);
  	}
  	return ret;

Maybe this is a good time to add some documentation above mddev_trylock() that explains the meaning of the return value? Anyway:

Reviewed-by on v1 1/1
#2 lore raw
In reply to Xiao Ni
Quoted 16 lines · Xiao Ni

A return value of 0 is treaded as successful lock acquisition. In fact, a return value of 1 means getting the lock successfully.

---
  drivers/md/md.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.h +0 -0
index 6985f2829bbd..3bfbee595156 100644

drivers/md/md.h static inline int mddev_trylock(struct mddev *mddev) · line 744

Quoted 10 lines
drivers/md/md.h +2 -2
@@ -737,8 +737,8 @@ static inline int mddev_trylock(struct mddev *mddev)
  	int ret;
 
  	ret = mutex_trylock(&mddev->reconfig_mutex);
-	if (!ret && test_bit(MD_DELETED, &mddev->flags)) {
-		ret = -ENODEV;
+	if (ret && test_bit(MD_DELETED, &mddev->flags)) {
+		ret = 0;
  		mutex_unlock(&mddev->reconfig_mutex);
  	}
  	return ret;

LGTM

Signature · 2 lines
Thanks,
Nan