Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp540790pxb; Thu, 9 Sep 2021 06:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJWwpZ0cF77FllHk+QsRVcz3ZPz7fBjhwQnBBDHhipLwIoHFbF8feGbZg+g5iuWm3bb+TY X-Received: by 2002:a5e:d80a:: with SMTP id l10mr2676454iok.36.1631195108621; Thu, 09 Sep 2021 06:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631195108; cv=none; d=google.com; s=arc-20160816; b=0Hn3xYutSwqQRrhZTbBF4IfcBoOznU5b86m5hdIZ0gR3CfYZApQ2w6ql+CXBHMNnQY 0JWwHe0gttfYkaEYaArPCuWq+h8wHGqDMsaidmvmFeC098rJ8p5fEoyeRVT8ZXI7vwYj qegMpHpCpwX80bwy+Zqh6OjPXvwPJqJRs4nWZqV8rCNRzpgsLJNDyluIhT0fkBwM8vI1 rwRkuX1nNOW2+BdFmRpUshu6/yFdviBrdXakLP8+9MXoXWGF9CxeTVQ6wazmOh8TbCP4 yl81hMrFFvLvAIYShCe7TiKRfodwBkL7CF2Uu/Qvh8HS1BMimQIHJXcMsjwU9uQVTVV1 BtZw== 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=E2rDgYjt4iGdcfzrWN5f0n9Far+R17aiysUYIbCrigo=; b=S1LP3sCNk6EnMJw9/7NWntr4HTM2q2CpzZxzDvG1fTJf5y/xD5MnQxUasjdjVs65lj wRvhIPHb1u9nWhMSqLXwtQIDJ4xbZFknpFkcc33KCuR7h/CoXqPGI3ujiK3KammD6m5h wjs4RKwMLS7N8UImrnoC4g15TAgEaIPFL7znGiDMK1MyPjbvMvBqJXTv67Ei4qZuz4l1 z39IjGuP3Sx2N/2fHKW53wKFnARx1TSnlIbBGw8upY9n/sljhiVS/3oJFOrxPqVnXoWU QYZ6SAL2IX5TyG0pEm0LXBQv3/z1L2oVcw20v3FHSyeJFpbxF0eEMYNhCmBAiQmyHU4w rclA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hlinMPMc; 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 126si1639989jaw.85.2021.09.09.06.44.53; Thu, 09 Sep 2021 06:45:08 -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=hlinMPMc; 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 S1356549AbhIINm4 (ORCPT + 99 others); Thu, 9 Sep 2021 09:42:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:41728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354613AbhIIMrU (ORCPT ); Thu, 9 Sep 2021 08:47:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 302A26320F; Thu, 9 Sep 2021 11:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188588; bh=YnPxrhg1s49V4lWDuTNR+ipJ7ngFuFI9dD3b1ucm4Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlinMPMc4Rx/HCSndH3dy2rDmge8l3Saox46aYshFwMpRBTEcGP0CDwQSTtVB+PXB wQLzY6FVTtP4b7kJpN/T6HMI+qt6cS20qfWTzcJ0qxjcOtjTNztLr11oE71XcE9XNN J8Inu84vbTAOMsFZyxEj/DcE83owx+K0CZaH2H4EeqvsJ8ZSMHvHY3w/rd+TpDqQ1D NBROvU3ahEQ5YgNHgpHOZfWI09j7MfRK5E93VsuSdOm279W1znK4jye0sDJmeGqKq3 AlfkMFdDLuweu8eX8XOwgPyA+RQ9k5m8VjpZV3+xr7bWDIzID6LnXfQlvsYfodX+TF NFGlKsz/qFTWQ== 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.4 063/109] drm/display: fix possible null-pointer dereference in dcn10_set_clock() Date: Thu, 9 Sep 2021 07:54:20 -0400 Message-Id: <20210909115507.147917-63-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115507.147917-1-sashal@kernel.org> References: <20210909115507.147917-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 60123db7ba02..bc5ebea1abed 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 @@ -3264,13 +3264,12 @@ static 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; @@ -3288,7 +3287,7 @@ static 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