Commit 99a27c08 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio: Split VFIO_GROUP_GET_STATUS into a function

This is the last sizable implementation in vfio_group_fops_unl_ioctl(),
move it to a function so vfio_group_fops_unl_ioctl() is emptied out.
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/8-v2-0f9e632d54fb+d6-vfio_ioctl_split_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent b3b43590
...@@ -1236,24 +1236,13 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group, ...@@ -1236,24 +1236,13 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
return ret; return ret;
} }
static long vfio_group_fops_unl_ioctl(struct file *filep, static int vfio_group_ioctl_get_status(struct vfio_group *group,
unsigned int cmd, unsigned long arg) struct vfio_group_status __user *arg)
{ {
struct vfio_group *group = filep->private_data; unsigned long minsz = offsetofend(struct vfio_group_status, flags);
void __user *uarg = (void __user *)arg;
long ret = -ENOTTY;
switch (cmd) {
case VFIO_GROUP_GET_DEVICE_FD:
return vfio_group_ioctl_get_device_fd(group, uarg);
case VFIO_GROUP_GET_STATUS:
{
struct vfio_group_status status; struct vfio_group_status status;
unsigned long minsz;
minsz = offsetofend(struct vfio_group_status, flags); if (copy_from_user(&status, arg, minsz))
if (copy_from_user(&status, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
if (status.argsz < minsz) if (status.argsz < minsz)
...@@ -1269,19 +1258,29 @@ static long vfio_group_fops_unl_ioctl(struct file *filep, ...@@ -1269,19 +1258,29 @@ static long vfio_group_fops_unl_ioctl(struct file *filep,
status.flags |= VFIO_GROUP_FLAGS_VIABLE; status.flags |= VFIO_GROUP_FLAGS_VIABLE;
up_read(&group->group_rwsem); up_read(&group->group_rwsem);
if (copy_to_user((void __user *)arg, &status, minsz)) if (copy_to_user(arg, &status, minsz))
return -EFAULT; return -EFAULT;
return 0;
}
ret = 0; static long vfio_group_fops_unl_ioctl(struct file *filep,
break; unsigned int cmd, unsigned long arg)
} {
struct vfio_group *group = filep->private_data;
void __user *uarg = (void __user *)arg;
switch (cmd) {
case VFIO_GROUP_GET_DEVICE_FD:
return vfio_group_ioctl_get_device_fd(group, uarg);
case VFIO_GROUP_GET_STATUS:
return vfio_group_ioctl_get_status(group, uarg);
case VFIO_GROUP_SET_CONTAINER: case VFIO_GROUP_SET_CONTAINER:
return vfio_group_ioctl_set_container(group, uarg); return vfio_group_ioctl_set_container(group, uarg);
case VFIO_GROUP_UNSET_CONTAINER: case VFIO_GROUP_UNSET_CONTAINER:
return vfio_group_ioctl_unset_container(group); return vfio_group_ioctl_unset_container(group);
default:
return -ENOTTY;
} }
return ret;
} }
static int vfio_group_fops_open(struct inode *inode, struct file *filep) static int vfio_group_fops_open(struct inode *inode, struct file *filep)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment