Merge tag 'iwlwifi-fixes-for-kalle-2014-12-18' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-block.git] / drivers / gpu / drm / amd / amdkfd / kfd_chardev.c
index 64c73bae960d7445589c08fbef16411f0cd2f230..4f7b275f2f7b0fdbb488055057c3291a1aab3a70 100644 (file)
@@ -102,15 +102,26 @@ struct device *kfd_chardev(void)
 static int kfd_open(struct inode *inode, struct file *filep)
 {
        struct kfd_process *process;
+       bool is_32bit_user_mode;
 
        if (iminor(inode) != 0)
                return -ENODEV;
 
+       is_32bit_user_mode = is_compat_task();
+
+       if (is_32bit_user_mode == true) {
+               dev_warn(kfd_device,
+                       "Process %d (32-bit) failed to open /dev/kfd\n"
+                       "32-bit processes are not supported by amdkfd\n",
+                       current->pid);
+               return -EPERM;
+       }
+
        process = kfd_create_process(current);
        if (IS_ERR(process))
                return PTR_ERR(process);
 
-       process->is_32bit_user_mode = is_compat_task();
+       process->is_32bit_user_mode = is_32bit_user_mode;
 
        dev_dbg(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
                process->pasid, process->is_32bit_user_mode);
@@ -149,7 +160,9 @@ static int set_queue_properties_from_user(struct queue_properties *q_properties,
        }
 
        if ((args->ring_base_address) &&
-               (!access_ok(VERIFY_WRITE, args->ring_base_address, sizeof(uint64_t)))) {
+               (!access_ok(VERIFY_WRITE,
+                       (const void __user *) args->ring_base_address,
+                       sizeof(uint64_t)))) {
                pr_err("kfd: can't access ring base address\n");
                return -EFAULT;
        }
@@ -159,12 +172,16 @@ static int set_queue_properties_from_user(struct queue_properties *q_properties,
                return -EINVAL;
        }
 
-       if (!access_ok(VERIFY_WRITE, args->read_pointer_address, sizeof(uint32_t))) {
+       if (!access_ok(VERIFY_WRITE,
+                       (const void __user *) args->read_pointer_address,
+                       sizeof(uint32_t))) {
                pr_err("kfd: can't access read pointer\n");
                return -EFAULT;
        }
 
-       if (!access_ok(VERIFY_WRITE, args->write_pointer_address, sizeof(uint32_t))) {
+       if (!access_ok(VERIFY_WRITE,
+                       (const void __user *) args->write_pointer_address,
+                       sizeof(uint32_t))) {
                pr_err("kfd: can't access write pointer\n");
                return -EFAULT;
        }
@@ -236,7 +253,7 @@ static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
        mutex_lock(&p->mutex);
 
        pdd = kfd_bind_process_to_device(dev, p);
-       if (IS_ERR(pdd) < 0) {
+       if (IS_ERR(pdd)) {
                err = PTR_ERR(pdd);
                goto err_bind_process;
        }
@@ -325,7 +342,9 @@ static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p,
        }
 
        if ((args.ring_base_address) &&
-               (!access_ok(VERIFY_WRITE, args.ring_base_address, sizeof(uint64_t)))) {
+               (!access_ok(VERIFY_WRITE,
+                       (const void __user *) args.ring_base_address,
+                       sizeof(uint64_t)))) {
                pr_err("kfd: can't access ring base address\n");
                return -EFAULT;
        }
@@ -381,7 +400,7 @@ static long kfd_ioctl_set_memory_policy(struct file *filep,
        mutex_lock(&p->mutex);
 
        pdd = kfd_bind_process_to_device(dev, p);
-       if (IS_ERR(pdd) < 0) {
+       if (IS_ERR(pdd)) {
                err = PTR_ERR(pdd);
                goto out;
        }