md: fix return value of mddev_trylock
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.
Fixes 9e59d609763f ("md: call del_gendisk in control path")
Reported-by Bart Van Assche <[email protected]>
Closes https://lore.kernel.org/linux-raid/[email protected]/T/#mfa369ef5faa4aa58e13e6d9fdb88aecd862b8f2f open here
Signed-off-by Xiao Ni <[email protected]>
--- drivers/md/md.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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;
Signature · 1 line
2.50.1 (Apple Git-155)
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.
Fixes 9e59d609763f ("md: call del_gendisk in control path")Reported-by Bart Van Assche <[email protected]>Closes https://lore.kernel.org/linux-raid/[email protected]/T/#mfa369ef5faa4aa58e13e6d9fdb88aecd862b8f2f open hereSigned-off-by Xiao Ni <[email protected]>--- drivers/md/md.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/md.h +0
-0
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 Bart Van Assche <[email protected]>
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.
Fixes 9e59d609763f ("md: call del_gendisk in control path")Reported-by Bart Van Assche <[email protected]>Closes https://lore.kernel.org/linux-raid/[email protected]/T/#mfa369ef5faa4aa58e13e6d9fdb88aecd862b8f2f open hereSigned-off-by Xiao Ni <[email protected]>--- drivers/md/md.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/md.h +0
-0
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
Reviewed-by Li Nan <[email protected]>
Signature · 2 lines
Thanks, Nan