From patchwork Wed Mar 24 12:17:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12160891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9474EC433DB for ; Wed, 24 Mar 2021 12:21:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33B95619CB for ; Wed, 24 Mar 2021 12:21:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33B95619CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=Svb1P8K3N61WCsrZ+R+ZEeJjE98j44VJKlIiWQUr9Jg=; b=DQEilms+928JJuHxuJrW39HMd5 XWC8om7LSN5+amtrR7asIeRq6lqZLc6dnGxkFNoJNjWO23s8PyEgMdrl7WhLf5hhiJsPJGF6ysrYt GmNC3H556P8a/UDeeiuufwvwOBVQTjabeitLcpHXTqT3v7VJcKhWArUbx/qpOeHDN75fqfZPWR/t4 A0hrPPqBUzy5ao8zI2/iLoj6NmtBO26VrcBw1Ka6TX0Mz917fyom7pR97FWdE6gXiPnrXy7G9cQ3I MZar1mgGcz+VADMXMF+c3uBuFMX7EKMmnCQ5U5kkbBrRv5CS6C17JIgTavfJyj7ywv2Y23xqU88Lp KpbtXVUA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lP2TE-00H25a-2l; Wed, 24 Mar 2021 12:18:44 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lP2TA-00H24N-4O for linux-arm-kernel@lists.infradead.org; Wed, 24 Mar 2021 12:18:42 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BCDD361A05; Wed, 24 Mar 2021 12:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616588318; bh=NbapMJTLgnN/hTMuqni8rldYG3iXiZwynRdZVPVSR3g=; h=From:To:Cc:Subject:Date:From; b=gDP58QSwtXffFOGt/cM15NaJiFb9eUeJH6dcmR7F7nEnjkeJDCpSHwo+m2kfrg5XR bRWV03IrQhy6kV7czeIzP2wFQ03EL4GGIzo/wcnyQVA4sdMsC4T6duwBGIVKgfL8Wl t/lPPfviNpQGo0twQRrJwCKBC6PhHvNZ/Vl0vA1bTeWQo6FNvUypNqbFbJl9Tf3rWQ hqlw4dQiFpyEHKlR0meAzJNYZlcgZ+/2iitl6pPKGbYCOGYCxyWDOeHcJP9r+qggAV vK9CubHtwy6ORV+UigJlaj+A77+ZoePMDDXbyl3LoCPilo19lAZ2ed33xT+Z5dTofI jNe0YoloU30LQ== From: Arnd Bergmann To: Philipp Zabel , David Airlie , Daniel Vetter Cc: Arnd Bergmann , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Laurent Pinchart , Joe Perches , Liu Ying , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] drm/imx: imx-ldb: fix out of bounds array access warning Date: Wed, 24 Mar 2021 13:17:59 +0100 Message-Id: <20210324121832.3714570-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210324_121840_432857_93143E42 X-CRM114-Status: GOOD ( 12.55 ) 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 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 --- v2: fix subject line expand patch description print mux number check upper bound as well --- drivers/gpu/drm/imx/imx-ldb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index dbfe39e2f7f6..40310327fa76 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -197,6 +197,12 @@ 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__, ERR_PTR(mux)); + return; + } + drm_panel_prepare(imx_ldb_ch->panel); if (dual) { @@ -255,6 +261,12 @@ 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__, ERR_PTR(mux)); + return; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__);