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 BC474C4167D for ; Sun, 12 Nov 2023 13:29:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A636610E30C; Sun, 12 Nov 2023 13:29:26 +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 989A610E303; Sun, 12 Nov 2023 13:29:23 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 4881AB807E8; Sun, 12 Nov 2023 13:29:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5BD0C43395; Sun, 12 Nov 2023 13:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795762; bh=ckoGjyC0/jwc26OxRRvzVlsmw9trxr1M39AQ/VPMYYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFXkIBSCFvzw76o/oq5omHADxxP18GsZOo4py3VPJyM1o4AY7xc1YRI2lrp2LyIVk 01PrSiuJVrqWPZCmBoKjzPYnHl+Q89x+aeKsEE/UoufcFlwtiDepqeQjKSbUlKLL+J iv+ehVO7kNi1eLpaFj9yXcmNsKqo2tRRLHrgdPAnKBjuvqatarzSnvCzSutDKSiI8V fqo7sWDWdxJUr+lYA7/EM7XYpQ7JbnQGtbz5v+ajUeA0ysGp+4DaXI7nSk90QxBsvf kKOIVcxNZdusLQ2GAsQ0OCVc7bKh2n9t0Mm2E3KKKfmeSkmJ9Dbczh32I5ySUNFGF5 qjSWNO6axqvJQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 5/5] drm/amd/display: Avoid NULL dereference of timing generator Date: Sun, 12 Nov 2023 08:29:12 -0500 Message-ID: <20231112132913.176824-5-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231112132913.176824-1-sashal@kernel.org> References: <20231112132913.176824-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.298 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx 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: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" 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 fdcc8ab19bf3f..25b8a8f933821 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c @@ -281,7 +281,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); @@ -305,7 +305,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