Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57093C072DD for ; Sun, 12 Nov 2023 13:29:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D30010E308; Sun, 12 Nov 2023 13:29:15 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 703FB10E306; Sun, 12 Nov 2023 13:29:13 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 2F1C7B80AD9; Sun, 12 Nov 2023 13:29:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9775AC433CD; Sun, 12 Nov 2023 13:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795751; bh=bQuLrl7Eqkhg2QhqvHqXpAKOXsUy12bgYjL3ovDnRxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGcaLwmjReLzKX/6xzSsjAkIWT+I1B+sIOiUyrb/3TENigg6GbCfi58ksLVnaVpWM M3xq2FOUwIkZ+neNZ/ux/ojZA9WjefYKNfWGlBwBRpSwHAkyW/VbcE5d9MgHnutCIT O+t+aq8UXLZLp5oKBrrI06wbmCnT8ACnjeS6QiC7XWhmOkqgk+PIfluyaPgFYGBXdD 7yypIdYjYkxEzjHBtMcKGaiCrK9tcl+vkEjW6zi0n8UGFUDetOgzGFQVieYYn1U+oU kOtZAlegRHa+Kdy0o8lLZmBwfJ7U55+b0xDESmXC3447ww2ZSKOSKQGEeks1wcyrUl Sxfu6u/7redgg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 6/6] drm/amd/display: Avoid NULL dereference of timing generator Date: Sun, 12 Nov 2023 08:29:00 -0500 Message-ID: <20231112132902.176672-6-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231112132902.176672-1-sashal@kernel.org> References: <20231112132902.176672-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.260 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , airlied@linux.ie, amd-gfx@lists.freedesktop.org, Daniel Wheeler , Hersen Wu , dri-devel@lists.freedesktop.org, Wayne Lin , Alex Deucher , Jun Lei , christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Wayne Lin [ Upstream commit b1904ed480cee3f9f4036ea0e36d139cb5fee2d6 ] [Why & How] Check whether assigned timing generator is NULL or not before accessing its funcs to prevent NULL dereference. Reviewed-by: Jun Lei Acked-by: Hersen Wu Signed-off-by: Wayne Lin Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c index bb09243758fe3..71b10b45a9b9e 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c @@ -492,7 +492,7 @@ uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream) for (i = 0; i < MAX_PIPES; i++) { struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg; - if (res_ctx->pipe_ctx[i].stream != stream) + if (res_ctx->pipe_ctx[i].stream != stream || !tg) continue; return tg->funcs->get_frame_count(tg); @@ -551,7 +551,7 @@ bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream, for (i = 0; i < MAX_PIPES; i++) { struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg; - if (res_ctx->pipe_ctx[i].stream != stream) + if (res_ctx->pipe_ctx[i].stream != stream || !tg) continue; tg->funcs->get_scanoutpos(tg, -- 2.42.0