Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4231517pxf; Tue, 23 Mar 2021 06:11:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfnZnRrWGQ8lwokPpLqRzE5sEOS3RM/r2xKYw/2XyCUECIwcYTNXUyWJKFknnHLIsBRAMu X-Received: by 2002:a17:906:d114:: with SMTP id b20mr4796630ejz.449.1616505070670; Tue, 23 Mar 2021 06:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616505070; cv=none; d=google.com; s=arc-20160816; b=r6JsI7nCwdrsPjb0eQp7U3uP4HpzbVisJIdGAeE0kx8dSZxWDWMVZR8LDvaXW9KCpW +y8R+2eMgpSD+vU43IzIQBvD7JIqot/Dlt/MBEBHfCcYJbhJrwEptM1obRo7Q4PgJC6+ /VG0EaOsK+vzWFW6YPjSfrcV2YEGOl/8FPCEnkEjA33A6Jk1SA2lG3k4ESBbMgiuOhbC nXpdPZ5tzEq/lTEPWsD/Wul+HuUR1kFUKEERUx1xiUdvZiKz+4xOtTw9Pm2aK19kh341 276uYLbswT8cHIMCBdCsPjSDUWoHVnnDuKyUJZqjO9bgyQzOa9oyB8nnZVyziyBePOTH RKqw== 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=6rNQVHmWGJasMU43Xr1tdbd6iI9sjoe3TduKM/fiB9c=; b=w9x243RQ5/UB+bdnkdljzm4BJmy2KPtTJNWoxvqJFGvkNPmu0Tysw2uIUYmIfsR595 lAhEszkbNuE/kuE5Jsb8uAM/rL2wBuOoziftc1oEFUiqIBsOheJsY48j8VbOA1AfvAnn sLNSZJkalZfDxpJZbj/v/337Cylet7hSBo7Z5/9cl3Hm0ZLpucFHCd5qspmnOZJXas4k BCDysPZPGOjPZ4NmTWnHEJD6RsEqXC2Gwp/SrPSA1cuqSj1/fYyc79+ZX8DDyN38xE6h X1EWdsdotmSq7sf/w0FWR6orUt2IEvko8Vxt7+9CV/Gzae5KEjzkG6MDSfhzSXJBMnud ecrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sXjI8Rlq; 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 dm14si12083670ejc.502.2021.03.23.06.10.44; Tue, 23 Mar 2021 06:11:10 -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=sXjI8Rlq; 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 S231211AbhCWNGX (ORCPT + 99 others); Tue, 23 Mar 2021 09:06:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:43252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231373AbhCWNFz (ORCPT ); Tue, 23 Mar 2021 09:05:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4D5E8619B6; Tue, 23 Mar 2021 13:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504755; bh=LElXukqBYdsmTv2ghODVkHwAAvlW3HFLLVGUeIbz0OA=; h=From:To:Cc:Subject:Date:From; b=sXjI8RlqjbU1oQkovu2toiAAKvGF09MicfaIGV9KdrzoOBNGDfaX4rOLl3/lwhBs6 r1zfIZXObRqW2n9r1Z1c6kymwz3x/+NwLIPTbWdk1Jfoxu6A2eqxwcGHBHPiHygIfu agCLOTf4Q4zuJlTVal8rYO3E9aeVVCx17MWH6d26QMjBiPUMi0Zxc1bfAo3cLv4yhV 4qGVwB7Qv0KVzLNLtsk46ehVDlQ9A9IPZBq3u8t/engD007SKu3f8c2Z7oBINnHQ0u 9jPfjcsb7aauRsuAYKBb4uJcqhHUaSs8mkOgG1CTmLDLi86XBZ8TV9eYPBSCAnQqCR acNGOM+BBihyg== From: Arnd Bergmann To: Philipp Zabel , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer Cc: Arnd Bergmann , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Joe Perches , Laurent Pinchart , Liu Ying , Thomas Zimmermann , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/imx: fix out of bounds array access warning Date: Tue, 23 Mar 2021 14:05:43 +0100 Message-Id: <20210323130550.2289487-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. Signed-off-by: Arnd Bergmann --- 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..1210360cec8a 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) { + dev_warn(ldb->dev, + "%s: invalid mux\n", __func__); + 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) { + dev_warn(ldb->dev, + "%s: invalid mux\n", __func__); + return; + } + if (mode->clock > 170000) { dev_warn(ldb->dev, "%s: mode exceeds 170 MHz pixel clock\n", __func__); -- 2.29.2