On Fri, Apr 15, 2022 at 03:44:56AM +0000, Tian, Kevin wrote: > > @@ -304,10 +309,10 @@ static int kvm_vfio_group_set_spapr_tce(struct > > kvm_device *dev, > > return -EBADF; > > > > vfio_group = kvm_vfio_group_get_external_user(f.file); > > - fdput(f); > > - > > - if (IS_ERR(vfio_group)) > > - return PTR_ERR(vfio_group); > > + if (IS_ERR(vfio_group)) { > > + ret = PTR_ERR(vfio_group); > > + goto err_fdput; > > + } > > > > grp = kvm_vfio_group_get_iommu_group(vfio_group); > > if (WARN_ON_ONCE(!grp)) { > > move above two external calls into below loop after file is > matched... Actually we can delete the kvm_vfio_group_get_external_user() since it is the same as kvg->vfio_group and we no longer need the group to match the kvg. > > @@ -320,7 +325,7 @@ static int kvm_vfio_group_set_spapr_tce(struct > > kvm_device *dev, > > mutex_lock(&kv->lock); > > > > list_for_each_entry(kvg, &kv->group_list, node) { > > - if (kvg->vfio_group != vfio_group) > > + if (kvg->filp != f.file) > > continue; > > ... here. Though they will be removed in later patch doing so at > this patch is slightly more reasonable. Sure, it is nicer Thanks, Jason