Re: [RFC PATCH 09/15] drivers/acrn: add passthrough device support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2019年08月16日 21:05, Dan Carpenter wrote:
On Fri, Aug 16, 2019 at 10:25:50AM +0800, Zhao Yakui wrote:
+	case IC_ASSIGN_PTDEV: {
+		unsigned short bdf;
+
+		if (copy_from_user(&bdf, (void *)ioctl_param,

This casting is ugly and you also need a __user tag for Sparse.  Do
something like "void __user *p = ioctl_param;"

Sure. The __user tag will be added for the ioctl_param parameter of copy_from/to_user.


+				   sizeof(unsigned short)))
+			return -EFAULT;
+
+		ret = hcall_assign_ptdev(vm->vmid, bdf);
+		if (ret < 0) {
+			pr_err("acrn: failed to assign ptdev!\n");
+			return -EFAULT;

Preserve the error code.  "return ret;".
Ok. It will preserver the err code.


+		}
+		break;
+	}
+	case IC_DEASSIGN_PTDEV: {
+		unsigned short bdf;
+
+		if (copy_from_user(&bdf, (void *)ioctl_param,
+				   sizeof(unsigned short)))
+			return -EFAULT;
+
+		ret = hcall_deassign_ptdev(vm->vmid, bdf);
+		if (ret < 0) {
+			pr_err("acrn: failed to deassign ptdev!\n");
+			return -EFAULT;
+		}
+		break;
+	}
+
+	case IC_SET_PTDEV_INTR_INFO: {
+		struct ic_ptdev_irq ic_pt_irq;
+		struct hc_ptdev_irq *hc_pt_irq;
+
+		if (copy_from_user(&ic_pt_irq, (void *)ioctl_param,
+				   sizeof(ic_pt_irq)))
+			return -EFAULT;
+
+		hc_pt_irq = kmalloc(sizeof(*hc_pt_irq), GFP_KERNEL);
+		if (!hc_pt_irq)
+			return -ENOMEM;
+
+		memcpy(hc_pt_irq, &ic_pt_irq, sizeof(*hc_pt_irq));

Use memdup_user().

OK. The memdup_user will be used.


+
+		ret = hcall_set_ptdev_intr_info(vm->vmid,
+						virt_to_phys(hc_pt_irq));
+		kfree(hc_pt_irq);
+		if (ret < 0) {
+			pr_err("acrn: failed to set intr info for ptdev!\n");
+			return -EFAULT;
+		}
+
+		break;
+	}

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux