aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2017-01-07 01:27:49 -0500
committerAlex Williamson <alex.williamson@redhat.com>2017-01-11 14:06:35 -0500
commit6ed0993a0b859ce62edf2930ded683e452286d39 (patch)
treed887337ec8e4b492163467fc95ef5672d35160aa
parenta121103c922847ba5010819a3f250f1f7fc84ab8 (diff)
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: 9d1a546c53b4 ("docs: Sample driver to demonstrate how to use Mediated device framework.") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--samples/vfio-mdev/mtty.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 1fc57a5093a7..975af5bbf28d 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1180,7 +1180,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
1180 1180
1181 memcpy(&mdev_state->dev_info, &info, sizeof(info)); 1181 memcpy(&mdev_state->dev_info, &info, sizeof(info));
1182 1182
1183 return copy_to_user((void __user *)arg, &info, minsz); 1183 if (copy_to_user((void __user *)arg, &info, minsz))
1184 return -EFAULT;
1185
1186 return 0;
1184 } 1187 }
1185 case VFIO_DEVICE_GET_REGION_INFO: 1188 case VFIO_DEVICE_GET_REGION_INFO:
1186 { 1189 {
@@ -1201,7 +1204,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
1201 if (ret) 1204 if (ret)
1202 return ret; 1205 return ret;
1203 1206
1204 return copy_to_user((void __user *)arg, &info, minsz); 1207 if (copy_to_user((void __user *)arg, &info, minsz))
1208 return -EFAULT;
1209
1210 return 0;
1205 } 1211 }
1206 1212
1207 case VFIO_DEVICE_GET_IRQ_INFO: 1213 case VFIO_DEVICE_GET_IRQ_INFO:
@@ -1224,7 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
1224 if (info.count == -1) 1230 if (info.count == -1)
1225 return -EINVAL; 1231 return -EINVAL;
1226 1232
1227 return copy_to_user((void __user *)arg, &info, minsz); 1233 if (copy_to_user((void __user *)arg, &info, minsz))
1234 return -EFAULT;
1235
1236 return 0;
1228 } 1237 }
1229 case VFIO_DEVICE_SET_IRQS: 1238 case VFIO_DEVICE_SET_IRQS:
1230 { 1239 {