drm/amdkfd: CRIU return -EFAULT for copy_to_user() failure
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 9 Feb 2022 18:09:59 +0000 (21:09 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 11 Feb 2022 21:10:06 +0000 (16:10 -0500)
If copy_to_user() fails, it returns the number of bytes remaining to
be copied but we want to return a negative error code (-EFAULT) to the
user.

Fixes: 9d5dabfeff3c ("drm/amdkfd: CRIU Save Shared Virtual Memory ranges")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: David Yat Sin <david.yatsin@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_svm.c

index e13ea97..7838266 100644 (file)
@@ -3771,10 +3771,10 @@ int kfd_criu_checkpoint_svm(struct kfd_process *p,
                        goto exit_priv;
                }
 
-               ret = copy_to_user(user_priv_data + *priv_data_offset,
-                                  svm_priv, svm_priv_data_size);
-               if (ret) {
+               if (copy_to_user(user_priv_data + *priv_data_offset, svm_priv,
+                                svm_priv_data_size)) {
                        pr_err("Failed to copy svm priv to user\n");
+                       ret = -EFAULT;
                        goto exit_priv;
                }