public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Deming Wang <wangdeming@inspur.com>
To: <pbonzini@redhat.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Deming Wang <wangdeming@inspur.com>
Subject: [PATCH] vfio: Use filp instead of fd
Date: Mon, 26 Sep 2022 02:54:07 -0400	[thread overview]
Message-ID: <20220926065407.2389-1-wangdeming@inspur.com> (raw)

The function of kvm_vfio_group_set_spapr_tce and kvm_vfio_group_del
use fd indirectly.But,it only be used for fd.file. So,we can directly
use the struct of file instead.

Signed-off-by: Deming Wang <wangdeming@inspur.com>
---
 virt/kvm/vfio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index ce1b01d02c51..3be84d82f905 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -178,11 +178,11 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
 {
 	struct kvm_vfio *kv = dev->private;
 	struct kvm_vfio_group *kvg;
-	struct fd f;
+	struct file *filp;
 	int ret;
 
-	f = fdget(fd);
-	if (!f.file)
+	filp = fget(fd);
+	if (!filp)
 		return -EBADF;
 
 	ret = -ENOENT;
@@ -190,7 +190,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
 	mutex_lock(&kv->lock);
 
 	list_for_each_entry(kvg, &kv->group_list, node) {
-		if (kvg->file != f.file)
+		if (kvg->file != filp)
 			continue;
 
 		list_del(&kvg->node);
@@ -207,7 +207,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
 
 	mutex_unlock(&kv->lock);
 
-	fdput(f);
+	fput(filp);
 
 	kvm_vfio_update_coherency(dev);
 
@@ -221,14 +221,14 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 	struct kvm_vfio_spapr_tce param;
 	struct kvm_vfio *kv = dev->private;
 	struct kvm_vfio_group *kvg;
-	struct fd f;
+	struct file *filp;
 	int ret;
 
 	if (copy_from_user(&param, arg, sizeof(struct kvm_vfio_spapr_tce)))
 		return -EFAULT;
 
-	f = fdget(param.groupfd);
-	if (!f.file)
+	filp = fget(param.groupfd);
+	if (!filp)
 		return -EBADF;
 
 	ret = -ENOENT;
@@ -238,13 +238,13 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 	list_for_each_entry(kvg, &kv->group_list, node) {
 		struct iommu_group *grp;
 
-		if (kvg->file != f.file)
+		if (kvg->file != filp)
 			continue;
 
 		grp = kvm_vfio_file_iommu_group(kvg->file);
 		if (WARN_ON_ONCE(!grp)) {
 			ret = -EIO;
-			goto err_fdput;
+			goto err_fput;
 		}
 
 		ret = kvm_spapr_tce_attach_iommu_group(dev->kvm, param.tablefd,
@@ -252,9 +252,9 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev,
 		break;
 	}
 
-err_fdput:
+err_fput:
 	mutex_unlock(&kv->lock);
-	fdput(f);
+	fput(filp);
 	return ret;
 }
 #endif
-- 
2.27.0


             reply	other threads:[~2022-09-26  7:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  6:54 Deming Wang [this message]
2022-09-26 13:23 ` [PATCH] vfio: Use filp instead of fd Al Viro
2022-09-26 17:07 ` Jason Gunthorpe
2022-09-26 19:38   ` Al Viro
  -- strict thread matches above, loose matches on Subject: below --
2022-09-27  1:21 tomorrow Wang (王德明)
2022-09-27  1:37 ` Al Viro
2022-09-27  1:25 tomorrow Wang (王德明)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220926065407.2389-1-wangdeming@inspur.com \
    --to=wangdeming@inspur.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox