gpu: ion: IOCTL return success when error occurs
authorOlav Haugan <ohaugan@codeaurora.org>
Fri, 13 Dec 2013 22:23:56 +0000 (14:23 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 14 Dec 2013 16:55:38 +0000 (08:55 -0800)
ION_IOC_MAP, ION_IOC_SHARE, and ION_IOC_IMPORT may return
success when an error occurs.

Add correct error handling to ION_IOC_MAP, ION_IOC_SHARE, and
ION_IOC_IMPORT.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
[jstultz: modified patch to apply to staging directory]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/ion/ion.c

index f536ce542782c2d8fe52caaca326d7cf5ac3a2e1..a054edd4195922c05b5021578704dcec1cad5b46 100644 (file)
@@ -1040,20 +1040,27 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                data.fd = ion_share_dma_buf(client, data.handle);
                if (copy_to_user((void __user *)arg, &data, sizeof(data)))
                        return -EFAULT;
+               if (data.fd < 0)
+                       return data.fd;
                break;
        }
        case ION_IOC_IMPORT:
        {
                struct ion_fd_data data;
+               int ret = 0;
                if (copy_from_user(&data, (void __user *)arg,
                                   sizeof(struct ion_fd_data)))
                        return -EFAULT;
                data.handle = ion_import_dma_buf(client, data.fd);
-               if (IS_ERR(data.handle))
+               if (IS_ERR(data.handle)) {
+                       ret = PTR_ERR(data.handle);
                        data.handle = NULL;
+               }
                if (copy_to_user((void __user *)arg, &data,
                                 sizeof(struct ion_fd_data)))
                        return -EFAULT;
+               if (ret < 0)
+                       return ret;
                break;
        }
        case ION_IOC_SYNC: