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: 13372389 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5D6ACCA0FE6 for ; Fri, 1 Sep 2023 09:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ufFwf8zIVi48kXbDMRijqpdVpAj4FM/2/NcJjZVRgrI=; b=Q5qj9riV6RXNOV Ki77lcYxbBn27d1kzL84FQTvuMRAe8C4+3OBnKMgUENUIgIknCBr8ORUbHdIq640t/tvrKDLuekdE WcGrmCot7VXDrBeH1wVgRfebJ7DPR95MkkAxOVuCVR374QR/4w/cfAb00CcSdy2v2uXOpvRCDQyrh 9hk9m4KB4RlZY7KmAG/C0dEupDZOVe1vzhlTyeKnUhSRa1GlOWizS0UQxdA13WG7BLhxep4lnvmMC RHNiCNgk/TEzwaLgr4fFTmCsxYE+5QgpDfM5cvHnMiQcGthrubeQC/PpSsUz22BTtT8sYQX1QPw3e avy2Yd/pB29pdG7LjElQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qc0wA-00GnG3-0L; Fri, 01 Sep 2023 09:59:34 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qc0w5-00GnES-2E; Fri, 01 Sep 2023 09:59:31 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230901_025929_937434_C591D758 X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jitao Shi , 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 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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"); From patchwork Fri Sep 1 09:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13372390 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5F4BACA0FE8 for ; Fri, 1 Sep 2023 09:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s0ENctjPhuDzW3khZGyQ34ovUUpM7DHPI1JBlWN5eu0=; b=1qxaCcL+HpHwPQ y5FNIChHMRU2gcUxeEoASs0BTA0r7b5Y/4XmRbIztcqHOp1yB5C+Zc6Fhq4ld/dYejcEqmqFbDoj1 U6exX7qz7LdbwBasnH7BCbVp4SOXw66QbvC44pGG4uc8zOTaZSmfn06UbH2CqdI66A/zhJLKhv6Fn JJrFMFNvnwsRe2w0PjfhGyiOCmKxxwV1Exk1x/fYIdqSPnQWLU0mWLhupTEpmT/YNIAu6wNnt4YVs cg7mCeEU/uZkuJ5UpXRiyMgushhkI9vgx9VIMrlPBnyV5rxvcydaR+P5aXNCLpJ1pfs/5jOyZtTgY sGZobCHDkUYzbsFsR+Lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qc0wB-00GnGi-0Z; Fri, 01 Sep 2023 09:59:35 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qc0w6-00GnEY-0R; Fri, 01 Sep 2023 09:59:31 +0000 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 dfw.source.kernel.org (Postfix) with ESMTPS id 9A89562B36; Fri, 1 Sep 2023 09:59:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A8ECC433CC; Fri, 1 Sep 2023 09:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693562368; bh=MCxcvPe7knGMaYt1Jtizlmz+R6LJpOaJGjbJJhZK6bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GA1YwEU3VH5nYETgRRFa+H2KhzO/6AeBueaJNaFrLhNj4oYVUrFlG31/kmDpBLfRN KdVdzl2z/1BnkOMivBAS/6T+XPYkzXOTvsxPcbU9MIIYd8aUuyjxmnemAWS+MU5o87 fcGo8kewyUkF4I7AwSdoDpAsP3/r/9nveK4GRIPBzah5737y3oGL7+eG4WTSqh8zqB I85097wIdGopqxEzor65wgSNmlLfntteEIlwPilu7+Rl8dMm7SJpbO7aMeFFCDgSVi bfMT1EVAaQiwlNfX43Y5NN2EFiE2jV0y66q8U8AtR+A1KBidHkIFVV3R4OcOPrWmfN m3cHUMKH7EWsw== 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 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Date: Fri, 1 Sep 2023 11:59:16 +0200 Message-Id: <20230901095916.3599320-2-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230901095916.3599320-1-mwalle@kernel.org> References: <20230901095916.3599320-1-mwalle@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230901_025930_281641_E31DA45A X-CRM114-Status: GOOD ( 17.84 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jitao Shi , 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 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org mtk_drm_find_possible_crtc_by_comp() assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment in mtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 1 and the third path will be 2. To fix that, dynamically calculate the IDs by the precence of the paths. Fixes: 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way") Suggested-by: Nícolas F. R. A. Prado Signed-off-by: Michael Walle Reviewed-by: Nícolas F. R. A. Prado Tested-by: Nícolas F. R. A. Prado --- v2: - iterate over all_drm_private[] to get any vdosys - new check if a path is available --- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 72 +++++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c index 771f4e173353..9f0f12740fb0 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -507,6 +507,27 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev, return false; } +static bool mtk_ddp_path_available(const unsigned int *path, + unsigned int path_len, + struct device_node **comp_node) +{ + unsigned int i; + + if (!path) + return false; + + for (i = 0U; i < path_len; i++) { + /* OVL_ADAPTOR doesn't have a device node */ + if (path[i] == DDP_COMPONENT_DRM_OVL_ADAPTOR) + continue; + + if (!comp_node[path[i]]) + return false; + } + + return true; +} + int mtk_ddp_comp_get_id(struct device_node *node, enum mtk_ddp_comp_type comp_type) { @@ -526,21 +547,44 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, struct device *dev) { struct mtk_drm_private *private = drm->dev_private; - unsigned int ret = 0; - - if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, private->data->main_len, - private->ddp_comp)) - ret = BIT(0); - else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path, - private->data->ext_len, private->ddp_comp)) - ret = BIT(1); - else if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path, - private->data->third_len, private->ddp_comp)) - ret = BIT(2); - else - DRM_INFO("Failed to find comp in ddp table\n"); + const struct mtk_mmsys_driver_data *data; + struct mtk_drm_private *priv_n; + int i = 0, j; + + for (j = 0; j < private->data->mmsys_dev_num; j++) { + priv_n = private->all_drm_private[j]; + data = priv_n->data; + + if (mtk_ddp_path_available(data->main_path, data->main_len, + priv_n->comp_node)) { + if (mtk_drm_find_comp_in_ddp(dev, priv_n->data->main_path, + priv_n->data->main_len, + priv_n->ddp_comp)) + return BIT(i); + i++; + } + + if (mtk_ddp_path_available(data->ext_path, data->ext_len, + priv_n->comp_node)) { + if (mtk_drm_find_comp_in_ddp(dev, priv_n->data->ext_path, + priv_n->data->ext_len, + priv_n->ddp_comp)) + return BIT(i); + i++; + } + + if (mtk_ddp_path_available(data->third_path, data->third_len, + priv_n->comp_node)) { + if (mtk_drm_find_comp_in_ddp(dev, priv_n->data->third_path, + priv_n->data->third_len, + priv_n->ddp_comp)) + return BIT(i); + i++; + } + } - return ret; + DRM_INFO("Failed to find comp in ddp table\n"); + return 0; } int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,