ptp: Fix some locking bugs in ptp_read()
authorDan Carpenter <error27@gmail.com>
Sun, 29 May 2011 19:54:07 +0000 (22:54 +0300)
committerJohn Stultz <john.stultz@linaro.org>
Thu, 2 Jun 2011 02:29:10 +0000 (19:29 -0700)
In ptp_read there is an unlock missing on an error path, and a double
unlock on another error path.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Acked-by: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: John Stultz <john.stultz@linaro.org>
drivers/ptp/ptp_chardev.c

index 93fa22de59773c51074103a06fd8c6118a843dd7..e7f301da290286153180fc5f1a9e02cdd9bb5f01 100644 (file)
@@ -130,8 +130,10 @@ ssize_t ptp_read(struct posix_clock *pc,
                return -ERESTARTSYS;
        }
 
-       if (ptp->defunct)
+       if (ptp->defunct) {
+               mutex_unlock(&ptp->tsevq_mux);
                return -ENODEV;
+       }
 
        spin_lock_irqsave(&queue->lock, flags);
 
@@ -151,10 +153,8 @@ ssize_t ptp_read(struct posix_clock *pc,
 
        mutex_unlock(&ptp->tsevq_mux);
 
-       if (copy_to_user(buf, event, cnt)) {
-               mutex_unlock(&ptp->tsevq_mux);
+       if (copy_to_user(buf, event, cnt))
                return -EFAULT;
-       }
 
        return cnt;
 }