From patchwork Tue Aug 29 13:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13368961 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 D1DCDC83F12 for ; Tue, 29 Aug 2023 13:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=n7WTqma7Qy0XC+p2KfuWbM1wjVTZVe7ioHmaOiReWA8=; b=1VBj9cHu3xRo2x aOMMMwRz/gsc9PXlRcMtC3Eqay8jzKJA9D2PiQIiB3A78hEUpvYV8JPRkHXSzGugu2jIn31seBbeY fMc/KHSxDDidKlSmkJyKVyeQTg7fAd2eNKC6NFXHZu9avNWqXayVGdSMeYSXKyTahaFgJWfp9ultj wob/cex2oLB5V/1o5b2o63WC2PSEKhg7RoIxZpT16/xdZewsKEblZ8BoxOVgcwkltLgD2UbW2NYHR SgdzdWDWk7xm7vgAClnBhQ93Jn3Ue0lbjMW4g0R6b+SN5NR1aFMnQG1xoom+Mob+HW/wxdhwELd4q VzWWg7GmM2ETPjfx6DXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qayds-00BZju-0U; Tue, 29 Aug 2023 13:20:24 +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 1qaydq-00BZjW-0T; Tue, 29 Aug 2023 13:20:23 +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 27950656A9; Tue, 29 Aug 2023 13:20:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B4F3C433C8; Tue, 29 Aug 2023 13:20:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693315220; bh=fokDp0Y3EnAwlAaygTWGT0A7Dg/k0huj36SykKsEO6Y=; h=From:To:Cc:Subject:Date:From; b=pC8tYIYstToTiPlNCSA6rH4DvNMTO8TuwNqOFxP0EK8hrjighEkXO7ppL56nIsaMU v2gR7SvJLwOMeEwvmIQc/qSBRpSNoAkt7DCnNzMrFGIKwbqwWbr07vBkBpztoJcQT8 WwzHHgYxVZppoh2f2VrfdChGUhOrGq3K2EaAxbJvLYUQ+AL0NfU1BDvaGqy1xBwbjG kyXmCWU5FY6aTpDr6RBDvO+WZHCkPKG/boO9nyXUUAolXIATWsPbhIMnNxVGSo17kI AW/EeIssueZgLVJ4o3WRNrKIdYByJrr5eOufNlpnNqFi+RBKwYJjL4E3tWK5Vfr+i/ kKLGDNrlMCFTw== 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 Cc: "Nancy . Lin" , Frank Wunderlich , Jitao Shi , Stu Hsieh , dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michael Walle Subject: [PATCH 1/2] drm/mediathek: fix kernel oops if no crtc is found Date: Tue, 29 Aug 2023 15:19:40 +0200 Message-Id: <20230829131941.3353439-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-20230829_062022_234048_C21C8EF4 X-CRM114-Status: GOOD ( 14.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org drm_crtc_from_index(0) might return NULL if there are not 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 --- 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 Tue Aug 29 13:19:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13368962 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 5B2D2C83F12 for ; Tue, 29 Aug 2023 13:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uOLKPoZn17Anpgr+Dr2kxas2ARgiyHssFz5rgADx5i0=; b=S6yEj7MZEcQXXy r9jIekH0WQ+R2Pil+7iqNVytOPMdHblJEQein/3MYI9fYiUUT8Ax62X7cW6abx7UWNgW6nGEt0YKl YY+cVmJMyadkvQNMmlUw9Zw+1/q0xSPLOFPe13ez4WHFp/4HbaiGToz4v6iXHKhZfIwiwnkP5XtDy DE425HsHuXthQxhmW7CJxpwD/6crBCbONDVnrVe+l3lwF8ryY/Koj5FFmq91Hcm7TmKYQik6JjUkx 0U/m4YwyMVKesfCPzn9QOJE8dxLxQJoovXJiHY2BmRrQRVG4mXlhybwdgQwPvm8xDLHEmMzIFycoY +AbS8IOEAiv6GbPurqIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qaye1-00BZm9-0f; Tue, 29 Aug 2023 13:20:33 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qaydx-00BZk7-2y; Tue, 29 Aug 2023 13:20: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 98E7A65266; Tue, 29 Aug 2023 13:20:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0331AC433CB; Tue, 29 Aug 2023 13:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693315224; bh=VmiiCQJmx/vUEhDJNuwCqJdIf0rnLGfJEi9IfqpWrHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NS5NeyHzBnEpCSp8tUcOhptK84Gn4+X+ta5XVY9kk0xU+tA6sgA9p6xWqjx/JL/nR fSVCOyncSFQy3jAIVO+vfbKbwmzBzfvykwgR18CuIfxtp4893xTNP/bWRXyYziGz3R dknzHrw6+ldB986WCqR7L0Y6hF+IlfZPrsEk3KXoz+y2a14lN8E6W2q2yymKdDLl4q ttO4a2hm8M9h4CXFmwHFFhAU7YspeVrR+PZntfgwPtbxvGfGAU52SzcUtBYttHSKqp TqBoM5xj1iHL0Ppn37bGy1ZhdqPmIBFIlh/k3NNWM2VWZ1U5Ulfj25h5Pd1YQhQ47O 9hFiSIDrm9Dzw== 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 Cc: "Nancy . Lin" , Frank Wunderlich , Jitao Shi , Stu Hsieh , dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michael Walle Subject: [PATCH 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Date: Tue, 29 Aug 2023 15:19:41 +0200 Message-Id: <20230829131941.3353439-2-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230829131941.3353439-1-mwalle@kernel.org> References: <20230829131941.3353439-1-mwalle@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230829_062030_045875_8D792570 X-CRM114-Status: GOOD ( 15.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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 --- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 41 ++++++++++++++------- 1 file changed, 27 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..f3064bff64e8 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -526,21 +526,34 @@ 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"); + int i = 0; + + if (private->data->main_path) { + if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, + private->data->main_len, + private->ddp_comp)) + return BIT(i); + i++; + } + + if (private->data->ext_path) { + if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path, + private->data->ext_len, + private->ddp_comp)) + return BIT(i); + i++; + } - return ret; + if (private->data->third_path) { + if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path, + private->data->third_len, + private->ddp_comp)) + return BIT(i); + i++; + } + + 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,