Commit 6ed0993a authored by Dan Carpenter's avatar Dan Carpenter Committed by Alex Williamson

vfio-mdev: return -EFAULT if copy_to_user() fails

The copy_to_user() function returns the number of bytes which it wasn't
able to copy but we want to return a negative error code.

Fixes: 9d1a546c ("docs: Sample driver to demonstrate how to use Mediated device framework.")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarKirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent a121103c
...@@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
memcpy(&mdev_state->dev_info, &info, sizeof(info)); memcpy(&mdev_state->dev_info, &info, sizeof(info));
return copy_to_user((void __user *)arg, &info, minsz); if (copy_to_user((void __user *)arg, &info, minsz))
return -EFAULT;
return 0;
} }
case VFIO_DEVICE_GET_REGION_INFO: case VFIO_DEVICE_GET_REGION_INFO:
{ {
...@@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
if (ret) if (ret)
return ret; return ret;
return copy_to_user((void __user *)arg, &info, minsz); if (copy_to_user((void __user *)arg, &info, minsz))
return -EFAULT;
return 0;
} }
case VFIO_DEVICE_GET_IRQ_INFO: case VFIO_DEVICE_GET_IRQ_INFO:
...@@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
if (info.count == -1) if (info.count == -1)
return -EINVAL; return -EINVAL;
return copy_to_user((void __user *)arg, &info, minsz); if (copy_to_user((void __user *)arg, &info, minsz))
return -EFAULT;
return 0;
} }
case VFIO_DEVICE_SET_IRQS: case VFIO_DEVICE_SET_IRQS:
{ {
......
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