Move it out of mtty_ioctl() and re-indent it.
Reviewed-by: Kevin Tian <[email protected]>
Acked-by: Pranjal Shrivastava <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
---
samples/vfio-mdev/mtty.c | 53 ++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 24 deletions(-)
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 59eefe2fed10ca..b27f9b93471bc5 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1785,6 +1785,34 @@ static int mtty_get_device_info(struct vfio_device_info
*dev_info)
return 0;
}
+static int mtty_ioctl_get_region_info(struct vfio_device *vdev,
+ struct vfio_region_info __user *arg)
+{
+ struct mdev_state *mdev_state =
+ container_of(vdev, struct mdev_state, vdev);
+ struct vfio_region_info info;
+ void *cap_type = NULL;
+ u16 cap_type_id = 0;
+ unsigned long minsz;
+ int ret;
+
+ minsz = offsetofend(struct vfio_region_info, offset);
+
+ if (copy_from_user(&info, arg, minsz))
+ return -EFAULT;
+
+ if (info.argsz < minsz)
+ return -EINVAL;
+
+ ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type);
+ if (ret)
+ return ret;
+
+ if (copy_to_user(arg, &info, minsz))
+ return -EFAULT;
+ return 0;
+}
+
static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
unsigned long arg)
{
@@ -1817,30 +1845,6 @@ static long mtty_ioctl(struct vfio_device *vdev,
unsigned int cmd,
return 0;
}
- case VFIO_DEVICE_GET_REGION_INFO:
- {
- struct vfio_region_info info;
- u16 cap_type_id = 0;
- void *cap_type = NULL;
-
- minsz = offsetofend(struct vfio_region_info, offset);
-
- if (copy_from_user(&info, (void __user *)arg, minsz))
- return -EFAULT;
-
- if (info.argsz < minsz)
- return -EINVAL;
-
- ret = mtty_get_region_info(mdev_state, &info, &cap_type_id,
- &cap_type);
- if (ret)
- return ret;
-
- if (copy_to_user((void __user *)arg, &info, minsz))
- return -EFAULT;
-
- return 0;
- }
case VFIO_DEVICE_GET_IRQ_INFO:
{
@@ -1949,6 +1953,7 @@ static const struct vfio_device_ops mtty_dev_ops = {
.read = mtty_read,
.write = mtty_write,
.ioctl = mtty_ioctl,
+ .get_region_info = mtty_ioctl_get_region_info,
.bind_iommufd = vfio_iommufd_emulated_bind,
.unbind_iommufd = vfio_iommufd_emulated_unbind,
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
--
2.43.0