<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <pre>Thanks for your feedback. We will prepare a V2 patch according to your advice.

Best wishes,
Tuo Li
</pre>
    <br>
    <div class="moz-cite-prefix">On 2021/8/10 21:38, Chen, Guchun wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:DM5PR12MB2469A884396F6018F8437E22F1F79@DM5PR12MB2469.namprd12.prod.outlook.com">
      <pre class="moz-quote-pre" wrap="">[Public]

Thanks for your patch.

I suggest moving the check of function pointer dc->clk_mgr->funcs->get_clock earlier, and return early if it's NULL, as if it's NULL, it's meaningless to continue the clock setting.

....
if (!dc->clk_mgr || !dc->clk_mgr->funcs->get_clock)
        return DC_FAIL_UNSUPPORTED_1;

dc->clk_mgr->funcs->get_clock(dc->clk_mgr,
        context, clock_type, &clock_cfg);
....

Regards,
Guchun

-----Original Message-----
From: amd-gfx <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx-bounces@lists.freedesktop.org"><amd-gfx-bounces@lists.freedesktop.org></a> On Behalf Of Tuo Li
Sent: Tuesday, August 10, 2021 5:20 PM
To: Wentland, Harry <a class="moz-txt-link-rfc2396E" href="mailto:Harry.Wentland@amd.com"><Harry.Wentland@amd.com></a>; Li, Sun peng (Leo) <a class="moz-txt-link-rfc2396E" href="mailto:Sunpeng.Li@amd.com"><Sunpeng.Li@amd.com></a>; Deucher, Alexander <a class="moz-txt-link-rfc2396E" href="mailto:Alexander.Deucher@amd.com"><Alexander.Deucher@amd.com></a>; Koenig, Christian <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a>; Pan, Xinhui <a class="moz-txt-link-rfc2396E" href="mailto:Xinhui.Pan@amd.com"><Xinhui.Pan@amd.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:airlied@linux.ie">airlied@linux.ie</a>; <a class="moz-txt-link-abbreviated" href="mailto:daniel@ffwll.ch">daniel@ffwll.ch</a>; Cyr, Aric <a class="moz-txt-link-rfc2396E" href="mailto:Aric.Cyr@amd.com"><Aric.Cyr@amd.com></a>; Lei, Jun <a class="moz-txt-link-rfc2396E" href="mailto:Jun.Lei@amd.com"><Jun.Lei@amd.com></a>; Zhuo, Qingqing <a class="moz-txt-link-rfc2396E" href="mailto:Qingqing.Zhuo@amd.com"><Qingqing.Zhuo@amd.com></a>; Siqueira, Rodrigo <a class="moz-txt-link-rfc2396E" href="mailto:Rodrigo.Siqueira@amd.com"><Rodrigo.Siqueira@amd.com></a>; Lee, Alvin <a class="moz-txt-link-rfc2396E" href="mailto:Alvin.Lee2@amd.com"><Alvin.Lee2@amd.com></a>; Stempen, Vladimir <a class="moz-txt-link-rfc2396E" href="mailto:Vladimir.Stempen@amd.com"><Vladimir.Stempen@amd.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:isabel.zhang@amd.com">isabel.zhang@amd.com</a>; Lee, Sung <a class="moz-txt-link-rfc2396E" href="mailto:Sung.Lee@amd.com"><Sung.Lee@amd.com></a>; Po-Yu Hsieh Paul <a class="moz-txt-link-rfc2396E" href="mailto:Paul.Hsieh@amd.com"><Paul.Hsieh@amd.com></a>; Wood, Wyatt <a class="moz-txt-link-rfc2396E" href="mailto:Wyatt.Wood@amd.com"><Wyatt.Wood@amd.com></a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>; <a class="moz-txt-link-abbreviated" href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a>; <a class="moz-txt-link-abbreviated" href="mailto:linux-kernel@vger.kernel.org">linux-kernel@vger.kernel.org</a>; <a class="moz-txt-link-abbreviated" href="mailto:baijiaju1990@gmail.com">baijiaju1990@gmail.com</a>; Tuo Li <a class="moz-txt-link-rfc2396E" href="mailto:islituo@gmail.com"><islituo@gmail.com></a>; TOTE Robot <a class="moz-txt-link-rfc2396E" href="mailto:oslab@tsinghua.edu.cn"><oslab@tsinghua.edu.cn></a>
Subject: [PATCH] drm/display: fix possible null-pointer dereference in dcn10_set_clock()

The variable dc->clk_mgr is checked in:
  if (dc->clk_mgr && dc->clk_mgr->funcs->get_clock)

This indicates dc->clk_mgr can be NULL.
However, it is dereferenced in:
  if (!dc->clk_mgr->funcs->get_clock)

To fix this possible null-pointer dereference, check dc->clk_mgr before dereferencing it.

Reported-by: TOTE Robot <a class="moz-txt-link-rfc2396E" href="mailto:oslab@tsinghua.edu.cn"><oslab@tsinghua.edu.cn></a>
Signed-off-by: Tuo Li <a class="moz-txt-link-rfc2396E" href="mailto:islituo@gmail.com"><islituo@gmail.com></a>
---
 drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
index c545eddabdcc..3a7c7c7efa68 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
@@ -3635,7 +3635,7 @@ enum dc_status dcn10_set_clock(struct dc *dc,
                                dc->clk_mgr->funcs->get_clock(dc->clk_mgr,
                                                context, clock_type, &clock_cfg);
 
-       if (!dc->clk_mgr->funcs->get_clock)
+       if (dc->clk_mgr && !dc->clk_mgr->funcs->get_clock)
                return DC_FAIL_UNSUPPORTED_1;
 
        if (clk_khz > clock_cfg.max_clock_khz)
--
2.25.1
</pre>
    </blockquote>
    <br>
  </body>
</html>