Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp532181pxf; Wed, 24 Mar 2021 09:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPNrCDGB01otoj2SQlFRbUswrV2Qf4gqH1RItyYWsR9BKCRpx4jxxNAwDshJiaIZHlFzy2 X-Received: by 2002:aa7:c14a:: with SMTP id r10mr4306198edp.132.1616604683322; Wed, 24 Mar 2021 09:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616604683; cv=none; d=google.com; s=arc-20160816; b=zXBhuU28dc+bBfuMUIHeb3mWzSMQlkL6a6yUnsR23aUWQVaR5fx0coIKh5hkuMFjRw 3BFKqgTqKLvETzyH0UaHvKPU6m306YdDGQP3TGwM+qHyB1jl6cTkTcLGw/v2d10o+UcJ XjZtiU/XMf1AUPMADuNEdFxAz0uDzyUYyrcWzTOucebZYnwWlRby9GdPB2WXK5G4fTkS 4mmQklerOCwryJp5dewcgl4zuXbUvf3/mVCSzTDae+rTUpu+4aHXptMibCp6sG0k3dbT Tf6PtltBs7NEYgVK/Egx713ILSQDRp/VZ5soYdSC/tTUY3q1G6oiSOIau5T4s6geX8UB hM6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=inh2LX5H8+ZgM/ZdHtKsLeuZ7wajWjx4AKJiIevEpcg=; b=JSxg8BksiCAHnt2j2n4L8f6Z0N/ZUNZZFRzELWTMYOlhq7CatiR76AhxyYGFp6HtFy Ca6trGXUoeLHnXWGt7bKghTvnGC9Qtj3wmIhDaTb79AM6QKuG8jPCoGZOFg0UszvB0vR 5mqmc0BllrNVcTcOUvaKSYBL0Trc1bDF3JCfl9cHBCY0U8JNUwg5U7mlXwN6Ys9XUMz7 x/PgGube2AhGcggUcVeA7TVgLQZ9VCcLgUii7q5ESeH8xWxC4Op2xsWmW5P9cerWzRHB 70Mme9Jflf64BLJRFRTJ/CtZJh6W3xt+5qsTmmXUI0fhEXsr3Hclm+3pQTg4Yx2/5U8l eHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QkfJpyXz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si2162125edr.434.2021.03.24.09.50.57; Wed, 24 Mar 2021 09:51:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QkfJpyXz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236440AbhCXQsJ (ORCPT + 99 others); Wed, 24 Mar 2021 12:48:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:43124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237003AbhCXQr4 (ORCPT ); Wed, 24 Mar 2021 12:47:56 -0400 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 Cc: Arnd Bergmann , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Sam Ravnborg , Liu Ying , Joe Perches , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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(+) 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__); -- 2.29.2