diff mbox series

[1/2] vfio/mlx5: fix error code in mlx5vf_precopy_ioctl()

Message ID Y5IKVknlf5Z5NPtU@kili (mailing list archive)
State New, archived
Headers show
Series [1/2] vfio/mlx5: fix error code in mlx5vf_precopy_ioctl() | expand

Commit Message

Dan Carpenter Dec. 8, 2022, 4:01 p.m. UTC
The copy_to_user() function returns the number of bytes remaining to
be copied but we want to return a negative error code here.

Fixes: 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/vfio/pci/mlx5/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Yishai Hadas Dec. 8, 2022, 4:21 p.m. UTC | #1
On 08/12/2022 18:01, Dan Carpenter wrote:
> The copy_to_user() function returns the number of bytes remaining to
> be copied but we want to return a negative error code here.
>
> Fixes: 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>   drivers/vfio/pci/mlx5/main.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
> index befdb0de32a1..83137228352e 100644
> --- a/drivers/vfio/pci/mlx5/main.c
> +++ b/drivers/vfio/pci/mlx5/main.c
> @@ -404,7 +404,10 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
>   
>   done:
>   	mlx5vf_state_mutex_unlock(mvdev);
> -	return copy_to_user((void __user *)arg, &info, minsz);
> +	if (copy_to_user((void __user *)arg, &info, minsz))
> +		return -EFAULT;
> +	return 0;
> +
>   err_migf_unlock:
>   	mutex_unlock(&migf->lock);
>   err_state_unlock:

Thanks Dan

Reviewed-by: Yishai Hadas <yishaih@nvidia.com>
Alex Williamson Dec. 8, 2022, 10:15 p.m. UTC | #2
On Thu, 8 Dec 2022 19:01:26 +0300
Dan Carpenter <error27@gmail.com> wrote:

> The copy_to_user() function returns the number of bytes remaining to
> be copied but we want to return a negative error code here.
> 
> Fixes: 0dce165b1adf ("vfio/mlx5: Introduce vfio precopy ioctl implementation")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>  drivers/vfio/pci/mlx5/main.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Applied both to vfio next branch for v6.2.  Thanks,

Alex
diff mbox series

Patch

diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
index befdb0de32a1..83137228352e 100644
--- a/drivers/vfio/pci/mlx5/main.c
+++ b/drivers/vfio/pci/mlx5/main.c
@@ -404,7 +404,10 @@  static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
 
 done:
 	mlx5vf_state_mutex_unlock(mvdev);
-	return copy_to_user((void __user *)arg, &info, minsz);
+	if (copy_to_user((void __user *)arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+
 err_migf_unlock:
 	mutex_unlock(&migf->lock);
 err_state_unlock: