Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp452479pxb; Thu, 9 Sep 2021 04:56:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx6nWmLZ38WSa5tclODIp84HWvq+sqjL/dh/tMD12tIGTlpworIue8Z6slstBWLI53aT/9 X-Received: by 2002:a05:6602:2001:: with SMTP id y1mr2322134iod.97.1631188611382; Thu, 09 Sep 2021 04:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188611; cv=none; d=google.com; s=arc-20160816; b=MWCYb5kSUU6fTsZApICiLIOLEQ1+0AzRDPKE8Q8v/Rk1WJhhI26dANN/53j1X+nDzw SLXoI+HdVv9aqauCqwGckVgwdAAjUWJOz8Ax1t+BZ2aChSdRVaX9BED30yJ0H2NObt8Z 45lpIopDWiE5YTAOf91m2oMoc5Ib3ji8DPXsiNkZ6r/uqW7JE80b6sEJvw+i9+t2Bv8V lFB9HnzmUMyqX2rEwry9zHK8nTAYKTAdb7T2FhKrYoYNvVN6u2AwBXenu+MACVWqq/Cg PVKVqAAkjNLFUHXrbhpytCC3tzUsQnRLAEGXya1k7Io++pJEeK7sqzuLKkmOki5xuQ0d 80qQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eTL5EuCLS6FK8NV4oyHzucrXsRhZ9BxAXzhMcKTbApQ=; b=Ndl6EzuIwRC82ZeXQwdttG4LBQD/dvic1LXmBBAgzMlNVEhMCuhVdQFAKUB4Btvbi6 Yb9FFb8IhPcaLEVLxdQC9WdRsoMZBbtDtOYd+ZIoYmRq1wTSK7VeYlQ/vXFgxZuRRjYp /1qLcCW0MSs2bo0gWsR6GNZmaNonF9kQbCd00uhpsi9AdvLWzbqlgqF59c8fNXap/JkD kak67VA1RwXuow8iBAFEvZEtZMq6Bysj7OQjvOj7IgpjVscYJ5JKb92uGETlCqiVCzo6 Lx1z1eY6cR6l1J0mq3PZlZ/68aJf1tmfCadDmcpa1Irh+bNzH6VBayPdJPMSuPNmXp2U HotQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ufjZFbID; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si1350608iog.114.2021.09.09.04.56.39; Thu, 09 Sep 2021 04:56:51 -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=@kernel.org header.s=k20201202 header.b=ufjZFbID; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242138AbhIIL5G (ORCPT + 99 others); Thu, 9 Sep 2021 07:57:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:54738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237419AbhIILwV (ORCPT ); Thu, 9 Sep 2021 07:52:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9094A61372; Thu, 9 Sep 2021 11:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187860; bh=5LuBohqvQBhRmRYfLetL1XDC8lNwVpB96plU8EyjnMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ufjZFbIDtH/Z1PlygCu0+XRxul0D4vk7yv330DCSH7D0qjWT7MftDcypZvJKwNu/G LEBudBfHomszFy8X3usc+kOHGWXySJ7muKT+rWjrlNmD9smJQr1zy9SJtPpnS9pJhF DiBGE51G25Ccq4W4ZR5YgTPtxYR2fS9kFN+C8KjP8EUM5A5RymQ3NqAjO4RKSx21bS bRFAKhAbJM6B5S+1X92aBa3nxRnqhS1gTlCraY4pQ4MELrCGIdtMsJ3fSXqfBB9KtM f53QIkvmAQVeq1Ha0b1ZroKWOkeRXNvoIYZFTtZmC2NZm4x4Y/E2pf2lrq6tnLcYif F0JD1UsdRJMRg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tuo Li , TOTE Robot , Alex Deucher , Sasha Levin , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.14 148/252] drm/display: fix possible null-pointer dereference in dcn10_set_clock() Date: Thu, 9 Sep 2021 07:39:22 -0400 Message-Id: <20210909114106.141462-148-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 dee1ce5f9609..75fa4adcf5f4 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 @@ -3628,13 +3628,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; @@ -3652,7 +3651,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