Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1706315pxb; Thu, 16 Sep 2021 13:30:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNpPzbVfmsJCPXzCYQY2UvU0CeVc7UlCuo43rhNOiAd7qS8MSJyzLRGpjwi9ybsnv1oeTo X-Received: by 2002:a05:6402:2048:: with SMTP id bc8mr8677680edb.114.1631824230648; Thu, 16 Sep 2021 13:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631824230; cv=none; d=google.com; s=arc-20160816; b=QUsAUwLs94e8zmu1cA8FvE1iiLI5gGdilvJjuTymoTPTCqln+3klZ86k1b4pILQM4h lF4f4RUtIWAKASCCWyK4sgv1dOy1YnRrFb6E4p6jBZc5c+qHYn5C72byjs8U5YX5rQg4 LI2nKrG2jY5VKP8lRleG5NWbCn8BJz9FT5ezVsD0o0/jZsJJp0tRe7lgUIpIhGZq1q2v 73ZnWPwm94TaMPcyn0PzMDs7u4ec6OfzbfKI1ruVLhp52EhjGH+DHNnkxfwB6J0qY/IY hUR/vk3EOs99UTTVb7QsQIsUNY82Hd9IFZWT6lkgMF5kZge6yNqlnKYV1QSF6RToqhIH jdoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KxrEcynTLnraQxSllY6seFQOWMh41F4cYs40Lcv6pS0=; b=CMMKYSGkfDEar9CvzlI5osP4llmNS2rrXhkoEMRrLgk4wiWeHVBl6pTni8pV8ZIPTr mZOqlxYGXaYjmS08HlnZPQiat37nG/yoBgaMvuDuF03tZrqyrHqoMNtdjJTKCWGWk0dO Tz3ABzTIrxCHFsrTN8y9gEr6EqKkcbiRIKqHa/UEXMIn3VgkCyFVbk3r0YbGN5jFzDpl oC9wMnxKBr1eKo4QUcxBMaOfeGABfSD8O4sb89PlPK+vFTQsqMShkfFoHgwBvgLXu7WR mxV0QIj0pn3m52O4z7kHfklBbatA81le9Zh+w5wrk3eW4HvZ6xpx18YfB/Oj4jVt2Nte CcjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0TNNX+Z3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf3si4790790edb.237.2021.09.16.13.30.06; Thu, 16 Sep 2021 13:30:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0TNNX+Z3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242584AbhIPQ2o (ORCPT + 99 others); Thu, 16 Sep 2021 12:28:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:59262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241665AbhIPQT6 (ORCPT ); Thu, 16 Sep 2021 12:19:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE43960F5B; Thu, 16 Sep 2021 16:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808834; bh=f/x94BKXVtLCgWGdN4LWr4PMGYpzsb3r3DjsQl4NM0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0TNNX+Z3Bi9ov/BUQm97o70lonXyiw1LyxKU1KIF4iwAbxLB6xn0nZWIu77oDdSYe Zlqkwf9s0kDmLbUMHRWyDA+/+/BzgLzaKjypdP2BhfljvHJvBFBfn0HHndoX9pZvJH Xiwq+UZAxcwhu6NIQXoDJGnMP0FrG5Wf+tzRDa9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TOTE Robot , Tuo Li , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 212/306] drm/display: fix possible null-pointer dereference in dcn10_set_clock() Date: Thu, 16 Sep 2021 17:59:17 +0200 Message-Id: <20210916155801.269374988@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tuo Li [ Upstream commit 554594567b1fa3da74f88ec7b2dc83d000c58e98 ] 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 null-pointer dereference, check dc->clk_mgr and the function pointer dc->clk_mgr->funcs->get_clock earlier, and return if one of them is NULL. Reported-by: TOTE Robot Signed-off-by: Tuo Li Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 0d1e7b56fb39..532f6a1145b5 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 @@ -3740,13 +3740,12 @@ enum dc_status dcn10_set_clock(struct dc *dc, struct dc_clock_config clock_cfg = {0}; struct dc_clocks *current_clocks = &context->bw_ctx.bw.dcn.clk; - if (dc->clk_mgr && dc->clk_mgr->funcs->get_clock) - 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; + dc->clk_mgr->funcs->get_clock(dc->clk_mgr, + context, clock_type, &clock_cfg); + if (clk_khz > clock_cfg.max_clock_khz) return DC_FAIL_CLK_EXCEED_MAX; @@ -3764,7 +3763,7 @@ enum dc_status dcn10_set_clock(struct dc *dc, else return DC_ERROR_UNEXPECTED; - if (dc->clk_mgr && dc->clk_mgr->funcs->update_clocks) + if (dc->clk_mgr->funcs->update_clocks) dc->clk_mgr->funcs->update_clocks(dc->clk_mgr, context, true); return DC_OK; -- 2.30.2