staging: sync: Fix error paths
authorRebecca Schultz Zavin <rebecca@android.com>
Fri, 1 Mar 2013 00:43:12 +0000 (16:43 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Mar 2013 09:44:08 +0000 (17:44 +0800)
Check the return value of get_unused_fd to make sure a valid
file descriptor is returned.

Make sure to call put_unused_fd even if an error occurs before
the fd can be used.

Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Erik Gilling <konkers@android.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Rob Clark <robclark@gmail.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: dri-devel@lists.freedesktop.org
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/sync.c

index 61c27bdc5d0bafe19f2bd47592fe3cc78c8c12c7..c4a3c1d7946c712dda286b301816b741ba9d1788 100644 (file)
@@ -647,8 +647,13 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
        struct sync_fence *fence2, *fence3;
        struct sync_merge_data data;
 
-       if (copy_from_user(&data, (void __user *)arg, sizeof(data)))
-               return -EFAULT;
+       if (fd < 0)
+               return fd;
+
+       if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+               err = -EFAULT;
+               goto err_put_fd;
+       }
 
        fence2 = sync_fence_fdget(data.fd2);
        if (fence2 == NULL) {