瀏覽代碼

vfio-pci: Use fdget() rather than eventfd_fget()

eventfd_fget() tests to see whether the file is an eventfd file, which
we then immediately pass to eventfd_ctx_fileget(), which again tests
whether the file is an eventfd file.  Simplify slightly by using
fdget() so that we only test that we're looking at an eventfd once.
fget() could also be used, but fdget() makes use of fget_light() for
another slight optimization.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Alex Williamson 12 年之前
父節點
當前提交
20e7745784
共有 1 個文件被更改,包括 16 次插入19 次删除
  1. 16 19
      drivers/vfio/pci/vfio_pci_intrs.c

+ 16 - 19
drivers/vfio/pci/vfio_pci_intrs.c

@@ -130,8 +130,8 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
 			 void (*thread)(struct vfio_pci_device *, void *),
 			 void (*thread)(struct vfio_pci_device *, void *),
 			 void *data, struct virqfd **pvirqfd, int fd)
 			 void *data, struct virqfd **pvirqfd, int fd)
 {
 {
-	struct file *file = NULL;
-	struct eventfd_ctx *ctx = NULL;
+	struct fd irqfd;
+	struct eventfd_ctx *ctx;
 	struct virqfd *virqfd;
 	struct virqfd *virqfd;
 	int ret = 0;
 	int ret = 0;
 	unsigned int events;
 	unsigned int events;
@@ -149,16 +149,16 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
 	INIT_WORK(&virqfd->shutdown, virqfd_shutdown);
 	INIT_WORK(&virqfd->shutdown, virqfd_shutdown);
 	INIT_WORK(&virqfd->inject, virqfd_inject);
 	INIT_WORK(&virqfd->inject, virqfd_inject);
 
 
-	file = eventfd_fget(fd);
-	if (IS_ERR(file)) {
-		ret = PTR_ERR(file);
-		goto fail;
+	irqfd = fdget(fd);
+	if (!irqfd.file) {
+		ret = -EBADF;
+		goto err_fd;
 	}
 	}
 
 
-	ctx = eventfd_ctx_fileget(file);
+	ctx = eventfd_ctx_fileget(irqfd.file);
 	if (IS_ERR(ctx)) {
 	if (IS_ERR(ctx)) {
 		ret = PTR_ERR(ctx);
 		ret = PTR_ERR(ctx);
-		goto fail;
+		goto err_ctx;
 	}
 	}
 
 
 	virqfd->eventfd = ctx;
 	virqfd->eventfd = ctx;
@@ -174,7 +174,7 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
 	if (*pvirqfd) {
 	if (*pvirqfd) {
 		spin_unlock_irq(&vdev->irqlock);
 		spin_unlock_irq(&vdev->irqlock);
 		ret = -EBUSY;
 		ret = -EBUSY;
-		goto fail;
+		goto err_busy;
 	}
 	}
 	*pvirqfd = virqfd;
 	*pvirqfd = virqfd;
 
 
@@ -187,7 +187,7 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
 	init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
 	init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
 	init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
 	init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
 
 
-	events = file->f_op->poll(file, &virqfd->pt);
+	events = irqfd.file->f_op->poll(irqfd.file, &virqfd->pt);
 
 
 	/*
 	/*
 	 * Check if there was an event already pending on the eventfd
 	 * Check if there was an event already pending on the eventfd
@@ -202,17 +202,14 @@ static int virqfd_enable(struct vfio_pci_device *vdev,
 	 * Do not drop the file until the irqfd is fully initialized,
 	 * Do not drop the file until the irqfd is fully initialized,
 	 * otherwise we might race against the POLLHUP.
 	 * otherwise we might race against the POLLHUP.
 	 */
 	 */
-	fput(file);
+	fdput(irqfd);
 
 
 	return 0;
 	return 0;
-
-fail:
-	if (ctx && !IS_ERR(ctx))
-		eventfd_ctx_put(ctx);
-
-	if (file && !IS_ERR(file))
-		fput(file);
-
+err_busy:
+	eventfd_ctx_put(ctx);
+err_ctx:
+	fdput(irqfd);
+err_fd:
 	kfree(virqfd);
 	kfree(virqfd);
 
 
 	return ret;
 	return ret;