]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdkfd: clean up the code to free hmm_range
authorSunil Khatri <sunil.khatri@amd.com>
Tue, 28 Oct 2025 08:19:24 +0000 (13:49 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 4 Nov 2025 16:33:53 +0000 (11:33 -0500)
a. hmm_range is either NULL or a valid pointer so we
do not need to set range to NULL ever.

b. keep the hmm_range_free in the end irrespective of
the other conditions to avoid some additional checks
and also avoid double free issue.

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_svm.c

index ffb7b36e577cdf1eeff4d225a9f75a2c6488f314..c30dfb8ec236375a60594221c38877be4138bdf7 100644 (file)
@@ -1744,11 +1744,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
                        else
                                r = -ENOMEM;
                        WRITE_ONCE(p->svms.faulting_task, NULL);
-                       if (r) {
-                               amdgpu_hmm_range_free(range);
-                               range = NULL;
+                       if (r)
                                pr_debug("failed %d to get svm range pages\n", r);
-                       }
                } else {
                        r = -EFAULT;
                }
@@ -1771,10 +1768,9 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
                        pr_debug("hmm update the range, need validate again\n");
                        r = -EAGAIN;
                }
-               /* Free the hmm range */
-               if (range)
-                       amdgpu_hmm_range_free(range);
 
+               /* Free the hmm range */
+               amdgpu_hmm_range_free(range);
 
                if (!r && !list_empty(&prange->child_list)) {
                        pr_debug("range split by unmap in parallel, validate again\n");