Skip to contentSkip to conversation

mshv_eventfd: convert to CLASS(fd)

PATCH In review Al Viro 3 participants 3 messages Jul 12, 2025 – Jul 15, 2025

Subsystems (3)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

PATCH 1/1 mshv_eventfd: convert to CLASS(fd)

[in viro/vfs.git #work.fd; if nobody objects, into #for-next it goes...]

similar to 66635b077624 ("assorted variants of irqfd setup: convert to CLASS(fd)") a year ago...

---

drivers/hv/mshv_eventfd.c +3 -11
index 8dd22be2ca0b..48c514da34eb 100644
@@ -377,10 +377,11 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL;
 	struct mshv_irqfd *irqfd, *tmp;
 	unsigned int events;
-	struct fd f;
 	int ret;
 	int idx;
 
+	CLASS(fd, f)(args->fd);
+
 	irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
 	if (!irqfd)
 		return -ENOMEM;
@@ -390,8 +391,7 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	INIT_WORK(&irqfd->irqfd_shutdown, mshv_irqfd_shutdown);
 	seqcount_spinlock_init(&irqfd->irqfd_irqe_sc, &pt->pt_irqfds_lock);
 
-	f = fdget(args->fd);
-	if (!fd_file(f)) {
+	if (fd_empty(f)) {
 		ret = -EBADF;
 		goto out;
 	}
@@ -496,12 +496,6 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 		mshv_assert_irq_slow(irqfd);
 
 	srcu_read_unlock(&pt->pt_irq_srcu, idx);
-	/*
-	 * do not drop the file until the irqfd is fully initialized, otherwise
-	 * we might race against the POLLHUP
-	 */
-	fdput(f);
-
 	return 0;
 
 fail:
@@ -514,8 +508,6 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	if (eventfd && !IS_ERR(eventfd))
 		eventfd_ctx_put(eventfd);
 
-	fdput(f);
-
 out:
 	kfree(irqfd);
 	return ret;
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Al Viro

[in viro/vfs.git #work.fd; if nobody objects, into #for-next it goes...]

similar to 66635b077624 ("assorted variants of irqfd setup: convert to CLASS(fd)") a year ago...

Thanks for the patch, Al.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Al Viro
Quoted 48 lines · Al Viro

[in viro/vfs.git #work.fd; if nobody objects, into #for-next it goes...]

similar to 66635b077624 ("assorted variants of irqfd setup: convert to CLASS(fd)") a year ago...

---

drivers/hv/mshv_eventfd.c +3 -9
index 8dd22be2ca0b..48c514da34eb 100644
@@ -377,10 +377,11 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL;
 	struct mshv_irqfd *irqfd, *tmp;
 	unsigned int events;
-	struct fd f;
 	int ret;
 	int idx;
 
+	CLASS(fd, f)(args->fd);
+
 	irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
 	if (!irqfd)
 		return -ENOMEM;
@@ -390,8 +391,7 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	INIT_WORK(&irqfd->irqfd_shutdown, mshv_irqfd_shutdown);
 	seqcount_spinlock_init(&irqfd->irqfd_irqe_sc, &pt->pt_irqfds_lock);
 
-	f = fdget(args->fd);
-	if (!fd_file(f)) {
+	if (fd_empty(f)) {
 		ret = -EBADF;
 		goto out;
 	}
@@ -496,12 +496,6 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 		mshv_assert_irq_slow(irqfd);
 
 	srcu_read_unlock(&pt->pt_irq_srcu, idx);
-	/*
-	 * do not drop the file until the irqfd is fully initialized, otherwise
-	 * we might race against the POLLHUP
-	 */
-	fdput(f);
-
 	return 0;
 
 fail:

drivers/hv/mshv_eventfd.c static int mshv_irqfd_assign(struct mshv_partition *pt, · line 513

Quoted 8 lines
drivers/hv/mshv_eventfd.c +0 -2
@@ -514,8 +508,6 @@ static int mshv_irqfd_assign(struct mshv_partition *pt,
 	if (eventfd && !IS_ERR(eventfd))
 		eventfd_ctx_put(eventfd);
 
-	fdput(f);
-
 out:
 	kfree(irqfd);
 	return ret;

Looks fine to me, thanks.