diff mbox

Btrfs-progs: scrub: don't call unlock if pthread_mutex_lock fails

Message ID 20140314234943.GA28451@localhost.localdomain (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Rakesh Pandit March 14, 2014, 11:49 p.m. UTC
If pthread_mutex_lock fails (rare but fix it anyway), don't call
pthread_mutex_unlock on mutex.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---
 cmds-scrub.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Rakesh Pandit March 15, 2014, 12:29 a.m. UTC | #1
Hi,

Forgot to mention the reason for change. If accepted this can be
included in commit message:

On Sat, Mar 15, 2014 at 01:49:45AM +0200, Rakesh Pandit wrote:
> If pthread_mutex_lock fails (rare but fix it anyway), don't call
> pthread_mutex_unlock on mutex.
>

Rationale being that if pthread_mutex_lock fails pthread_mutex_unlock
will always fail and overwrite actual error value in err.
 
> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>

regards,
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba March 17, 2014, 12:44 p.m. UTC | #2
On Sat, Mar 15, 2014 at 02:29:33AM +0200, Rakesh Pandit wrote:
> Forgot to mention the reason for change. If accepted this can be
> included in commit message:
> 
> Rationale being that if pthread_mutex_lock fails pthread_mutex_unlock
> will always fail and overwrite actual error value in err.

Thanks, updated.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 128537b..ca11fb5 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -776,7 +776,7 @@  static int scrub_write_progress(pthread_mutex_t *m, const char *fsid,
 	ret = pthread_mutex_lock(m);
 	if (ret) {
 		err = -ret;
-		goto out;
+		goto fail;
 	}
 
 	ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old);
@@ -808,6 +808,7 @@  out:
 	if (ret && !err)
 		err = -ret;
 
+fail:
 	ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
 	if (ret && !err)
 		err = -ret;