<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">2025年1月8日 06:53,Chen, Xiaogang <<a href="mailto:xiaogang.chen@amd.com" class="">xiaogang.chen@amd.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
  
  <div class=""><p class=""><br class="">
    </p>
    <div class="moz-cite-prefix">On 1/4/2025 8:45 PM, Jiang Liu wrote:<br class="">
    </div>
    <blockquote type="cite" cite="mid:70f5963233c8a34354ec8a9efebc3a7b4c7940d4.1736044362.git.gerry@linux.alibaba.com" class="">
      <pre wrap="" class="moz-quote-pre">Fix possible resource leakage on error recovery path in function
kgd2kfd_device_init().

Signed-off-by: Jiang Liu <a class="moz-txt-link-rfc2396E" href="mailto:gerry@linux.alibaba.com"><gerry@linux.alibaba.com></a>
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index a29374c86405..fa5054940486 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -898,15 +898,15 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
                if (kfd->adev->xcp_mgr)
                        kfd_setup_interrupt_bitmap(node, i);
 
+               spin_lock_init(&node->watch_points_lock);
+
+               kfd->nodes[i] = node;
+
                /* Initialize the KFD node */
                if (kfd_init_node(node)) {
                        dev_err(kfd_device, "Error initializing KFD node\n");
                        goto node_init_error;
                }
-
-               spin_lock_init(&node->watch_points_lock);
-
-               kfd->nodes[i] = node;
        }
 
        svm_range_set_max_pages(kfd->adev);
@@ -921,6 +921,7 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
        goto out;
 
 node_init_error:
+       i++;
 node_alloc_error:
        kfd_cleanup_nodes(kfd, i);
        kfd_doorbell_fini(kfd);</pre>
    </blockquote><p class="">I think this change is not right: if <span style="white-space: pre-wrap" class="">kfd_init_node</span> fail it does
      clean up for the kfd_node that it is initializing internally. <span style="white-space: pre-wrap" class="">kfd_cleanup_nodes</span> does not
      need to clean up the kfd node i which failed to init, just clean
      up the kfd_nodes that were initialized previously.</p></div></div></blockquote>Yes, I made a mistake here and will drop this patch in next version.</div><div><br class=""></div><div>Thanks,</div><div>Gerry<br class=""><blockquote type="cite" class=""><div class=""><div class=""><p class="">Regard</p><p class="">Xiaogang<br class="">
    </p>
    <blockquote type="cite" cite="mid:70f5963233c8a34354ec8a9efebc3a7b4c7940d4.1736044362.git.gerry@linux.alibaba.com" class="">
      <pre wrap="" class="moz-quote-pre"></pre>
    </blockquote>
  </div>

</div></blockquote></div><br class=""></body></html>