From patchwork Fri Sep 1 09:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13372395 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 C1610CA0FE1 for ; Fri, 1 Sep 2023 10:10:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00EBC10E774; Fri, 1 Sep 2023 10:10:04 +0000 (UTC) X-Greylist: delayed 632 seconds by postgrey-1.36 at gabe; Fri, 01 Sep 2023 10:10:02 UTC Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8437610E774 for ; Fri, 1 Sep 2023 10:10:02 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id AFF4BCE2379; Fri, 1 Sep 2023 09:59:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAD1DC433C8; Fri, 1 Sep 2023 09:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693562365; bh=plaayqcwd0Pw1QVSUvWUHkum1RtiVPbMvX2UxvCAEBg=; h=From:To:Cc:Subject:Date:From; b=fqo6BnowGrrTIQ/G74gBuald2l0dxpDLr0nl0puQP6QNdZH+Z2RW3YmtyTcZXlt+Z tSq5cG2YmTa0MbYJi9hJap1fvbcdfgo2WaEksdNnocXSRUDrr9G41yQrTkm1aGiUDo GtOWGih0DO0nZ3h0w3DebFG1HqCcpPtw7ifEXRh+rnZd0kFhvHx2EBbWle/SC7CMeX 4V2tKNMXkZd6IZboJ/c6HTGUq5iWlto1/E7l8JR/FxXKPWRCYH/89TDvGGhUBg7JBj VRvkPZTvX0FFJ46Wus2YB0x+RbfGB50+gzTKW5pgQUJBPuNGK6/B0Ctd/vMacRL4Zu L5uU0CiGhQgcQ== From: Michael Walle To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Chun-Kuang Hu , Philipp Zabel , David Airlie , Daniel Vetter , Matthias Brugger , AngeloGioacchino Del Regno Subject: [PATCH v2 1/2] drm/mediatek: fix kernel oops if no crtc is found Date: Fri, 1 Sep 2023 11:59:15 +0200 Message-Id: <20230901095916.3599320-1-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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: Jitao Shi , Frank Wunderlich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Nancy . Lin" , linux-mediatek@lists.infradead.org, Stu Hsieh , Michael Walle , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm_crtc_from_index(0) might return NULL if there are no CRTCs registered at all which will lead to a kernel oops in mtk_drm_crtc_dma_dev_get(). Add the missing return value check. Fixes: 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195") Signed-off-by: Michael Walle Reviewed-by: NĂ­colas F. R. A. Prado Tested-by: NĂ­colas F. R. A. Prado --- v2: - collected tags - fixed typos --- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index 93552d76b6e7..2c582498817e 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -420,6 +420,7 @@ static int mtk_drm_kms_init(struct drm_device *drm) struct mtk_drm_private *private = drm->dev_private; struct mtk_drm_private *priv_n; struct device *dma_dev = NULL; + struct drm_crtc *crtc; int ret, i, j; if (drm_firmware_drivers_only()) @@ -494,7 +495,9 @@ static int mtk_drm_kms_init(struct drm_device *drm) } /* Use OVL device for all DMA memory allocations */ - dma_dev = mtk_drm_crtc_dma_dev_get(drm_crtc_from_index(drm, 0)); + crtc = drm_crtc_from_index(drm, 0); + if (crtc) + dma_dev = mtk_drm_crtc_dma_dev_get(crtc); if (!dma_dev) { ret = -ENODEV; dev_err(drm->dev, "Need at least one OVL device\n");