From patchwork Wed Mar 24 16:47:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 408169 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp568743jai; Wed, 24 Mar 2021 09:47:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP4lMc2PFbbdWhaj1Av6yWF8KY7203PB2LyNsnLkxEqaxPuH+XI4gPIzBRedzSacsAZtHl X-Received: by 2002:a17:90b:1213:: with SMTP id gl19mr4326715pjb.55.1616604479435; Wed, 24 Mar 2021 09:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616604479; cv=none; d=google.com; s=arc-20160816; b=hIKiklbvvEJtf7nBRzBrwvFctofojZw5sox9lp7MgkYRUJ8vtwxzfgXe7tNXoQXlYx myBOJI5ER29yObqXqWsd0PHo6QvMp52uW6VFyRrDoTtXlsNp4KVYamSb4k3XuoITxjbm DiKO5Okbe0s9onUX1jF7kBSBG02SmFUVB48vt9I1tXG20iFCrWBwaggrIFgCnkvCUSlT jtY+qwd7y0ZWtExoflT3SVmG0IijdwN7f6u9DVPU8PCHrrWQPZ6XLs2Kajx+sp+v53EM yikR06CI+vt2uUyfbABSSfcDrkCfQOzDRTNRRGQChk6B6WQJ5/eyLFfkq80i9w0hxBPi 600g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:delivered-to; bh=TLYc8uyh0W2509RLpAWcTtw79kwYfBpPd1kKGOKuxrQ=; b=W8XzBGLfmrb4pNKlqPEIxG/dj5zrpiBIjshLA6THXwF52+ibTuepiphKy5LQoOGbDd ZqS7cbuRWhILHa4Guri6VCSsmUmGKEUm46dke7fpkypaUgV0TKVg49/CeG/pNjCrWb+Q 9eAiFgwPdICefxjdimQ6csqgixuveIEuBzehwA9qtWPxTyTJZG/xvUoi5+3RnU3Jb6uK 7B12GSWytRsW2HdeqBgCyeK4TVMLjjZF9mBnsE4ssgFeMd5yJdudCVsC8Kij5Bh0o+ip 4cPlzk3sa5cfMkr9kbSfp2KwN9wK9Moa8CSG8evAH2qLB3wbS6nSv99Sl2UqXcnS7Rbz 2U4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=QkfJpyXz; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 17si2808840pfw.63.2021.03.24.09.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 09:47:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=QkfJpyXz; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 561796EA3C; Wed, 24 Mar 2021 16:47:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 06D7A6EA3C for ; Wed, 24 Mar 2021 16:47:56 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 05AC361A06; Wed, 24 Mar 2021 16:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616604475; bh=p+1TIRUmePIQc6WtQPg9mzBzgEJQ9OP7+R0w8iP3j40=; h=From:To:Cc:Subject:Date:From; b=QkfJpyXzcvwWQuYP12k3YP8sS65dUJpTatoatVEjc43JkFpqNlUPVsjzAWuKoY5I1 UxhZ0t3EY/Rbro2FE9s1zYHRnW2j85Sosjb7WwGb1Y4aVor5j1JFsaMEHE8WC/PCxX vBW+zFJd++kSDgxH9mTh4ye9GM4THg70dyEfo5M9GOc6Gd87o9aKYwuS6GnQAY1iIn DP6X5xi4D+OBiWLQqIl2IrgMn/7I08Rqw7kVDZc+lg+wgvVTuHDtX8Xdy6+DdBWbzp tqM2UL+3JcpY0uU8VW5gbLn62vAqS61OF7kSTn1CLGc3KeyrFQCFLQDVVLKU7HvgOF DC+FNlt5ne5og== From: Arnd Bergmann To: Philipp Zabel , David Airlie , Daniel Vetter Subject: [PATCH] [v3] drm/imx: imx-ldb: fix out of bounds array access warning Date: Wed, 24 Mar 2021 17:47:41 +0100 Message-Id: <20210324164750.3833773-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.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: Arnd Bergmann , Liu Ying , Shawn Guo , Sascha Hauer , Marco Felsch , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sam Ravnborg , NXP Linux Team , Pengutronix Kernel Team , Joe Perches , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann When CONFIG_OF is disabled, building with 'make W=1' produces warnings about out of bounds array access: drivers/gpu/drm/imx/imx-ldb.c: In function 'imx_ldb_set_clock.constprop': drivers/gpu/drm/imx/imx-ldb.c:186:8: error: array subscript -22 is below array bounds of 'struct clk *[4]' [-Werror=array-bounds] Add an error check before the index is used, which helps with the warning, as well as any possible other error condition that may be triggered at runtime. The warning could be fixed by adding a Kconfig depedency on CONFIG_OF, but Liu Ying points out that the driver may hit the out-of-bounds problem at runtime anyway. Signed-off-by: Arnd Bergmann --- v3: fix build regression from v2 v2: fix subject line expand patch description print mux number check upper bound as well --- drivers/gpu/drm/imx/imx-ldb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.29.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel Reviewed-by: Liu Ying diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index dbfe39e2f7f6..565482e2b816 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -197,6 +197,11 @@ static void imx_ldb_encoder_enable(struct drm_encoder *encoder) int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); + if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { + dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux); + return; + } + drm_panel_prepare(imx_ldb_ch->panel); if (dual) { @@ -255,6 +260,11 @@ imx_ldb_encoder_atomic_mode_set(struct drm_encoder *encoder, int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); u32 bus_format = imx_ldb_ch->bus_format; + if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { + dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux); + return; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__);