diff mbox series

[v2,7/8] vfio: Follow the naming pattern for vfio_group_ioctl_unset_container()

Message ID 7-v2-0f9e632d54fb+d6-vfio_ioctl_split_jgg@nvidia.com (mailing list archive)
State New, archived
Headers show
Series Break up ioctl dispatch functions to one function per ioctl | expand

Commit Message

Jason Gunthorpe Aug. 31, 2022, 8:16 p.m. UTC
Make it clear that this is the body of the ioctl. Fold the locking into
the function so it is self contained like the other ioctls.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_main.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

Comments

Tian, Kevin Sept. 1, 2022, 2:20 a.m. UTC | #1
> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Thursday, September 1, 2022 4:16 AM
> 
> Make it clear that this is the body of the ioctl. Fold the locking into
> the function so it is self contained like the other ioctls.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff mbox series

Patch

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 17c44ee81f9fea..0bb75416acfc49 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -968,16 +968,24 @@  static void __vfio_group_unset_container(struct vfio_group *group)
  * the group, we know that still exists, therefore the only valid
  * transition here is 1->0.
  */
-static int vfio_group_unset_container(struct vfio_group *group)
+static int vfio_group_ioctl_unset_container(struct vfio_group *group)
 {
-	lockdep_assert_held_write(&group->group_rwsem);
+	int ret = 0;
 
-	if (!group->container)
-		return -EINVAL;
-	if (group->container_users != 1)
-		return -EBUSY;
+	down_write(&group->group_rwsem);
+	if (!group->container) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+	if (group->container_users != 1) {
+		ret = -EBUSY;
+		goto out_unlock;
+	}
 	__vfio_group_unset_container(group);
-	return 0;
+
+out_unlock:
+	up_write(&group->group_rwsem);
+	return ret;
 }
 
 static int vfio_group_ioctl_set_container(struct vfio_group *group,
@@ -1270,10 +1278,7 @@  static long vfio_group_fops_unl_ioctl(struct file *filep,
 	case VFIO_GROUP_SET_CONTAINER:
 		return vfio_group_ioctl_set_container(group, uarg);
 	case VFIO_GROUP_UNSET_CONTAINER:
-		down_write(&group->group_rwsem);
-		ret = vfio_group_unset_container(group);
-		up_write(&group->group_rwsem);
-		break;
+		return vfio_group_ioctl_unset_container(group);
 	}
 
 	return ret;