linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Liu Ying <victor.liu@nxp.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 05/25] drm/imx: imx-ldb: fix out of bounds array access warning
Date: Thu, 15 Apr 2021 16:47:59 +0200	[thread overview]
Message-ID: <20210415144413.334856476@linuxfoundation.org> (raw)
In-Reply-To: <20210415144413.165663182@linuxfoundation.org>

From: Arnd Bergmann <arnd@arndb.de>

[ Upstream commit 33ce7f2f95cabb5834cf0906308a5cb6103976da ]

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 <arnd@arndb.de>
Reviewed-by: Liu Ying <victor.liu@nxp.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 41e2978cb1eb..75036aaa0c63 100644
--- a/drivers/gpu/drm/imx/imx-ldb.c
+++ b/drivers/gpu/drm/imx/imx-ldb.c
@@ -190,6 +190,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) {
@@ -248,6 +253,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.30.2




  parent reply	other threads:[~2021-04-15 15:13 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 14:47 [PATCH 5.10 00/25] 5.10.31-rc1 review Greg Kroah-Hartman
2021-04-15 14:47 ` [PATCH 5.10 01/25] interconnect: core: fix error return code of icc_link_destroy() Greg Kroah-Hartman
2021-04-15 14:47 ` [PATCH 5.10 02/25] gfs2: Flag a withdraw if init_threads() fails Greg Kroah-Hartman
2021-04-15 14:47 ` [PATCH 5.10 03/25] KVM: arm64: Hide system instruction access to Trace registers Greg Kroah-Hartman
2021-04-15 14:47 ` [PATCH 5.10 04/25] KVM: arm64: Disable guest access to trace filter controls Greg Kroah-Hartman
2021-04-15 14:47 ` Greg Kroah-Hartman [this message]
2021-04-15 14:48 ` [PATCH 5.10 06/25] gfs2: report "already frozen/thawed" errors Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 07/25] ftrace: Check if pages were allocated before calling free_pages() Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 08/25] tools/kvm_stat: Add restart delay Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 09/25] drm/tegra: dc: Dont set PLL clock to 0Hz Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 10/25] gpu: host1x: Use different lock classes for each client Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 11/25] XArray: Fix splitting to non-zero orders Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 12/25] radix tree test suite: Fix compilation Greg Kroah-Hartman
2021-04-15 15:12   ` Matthew Wilcox
2021-04-16  0:06     ` Sasha Levin
2021-04-15 14:48 ` [PATCH 5.10 13/25] block: only update parent bi_status when bio fail Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 14/25] radix tree test suite: Register the main thread with the RCU library Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 15/25] idr test suite: Take RCU read lock in idr_find_test_1 Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 16/25] idr test suite: Create anchor before launching throbber Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 17/25] null_blk: fix command timeout completion handling Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 18/25] io_uring: dont mark S_ISBLK async work as unbounded Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 19/25] riscv,entry: fix misaligned base for excp_vect_table Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 20/25] block: dont ignore REQ_NOWAIT for direct IO Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 21/25] netfilter: x_tables: fix compat match/target pad out-of-bound write Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 22/25] perf map: Tighten snprintf() string precision to pass gcc check on some 32-bit arches Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 23/25] net: sfp: relax bitrate-derived mode check Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 24/25] net: sfp: cope with SFPs that set both LOS normal and LOS inverted Greg Kroah-Hartman
2021-04-15 14:48 ` [PATCH 5.10 25/25] xen/events: fix setting irq affinity Greg Kroah-Hartman
2021-04-15 19:11 ` [PATCH 5.10 00/25] 5.10.31-rc1 review Pavel Machek
2021-04-15 20:03 ` Andrei Rabusov
2021-04-15 22:42 ` Shuah Khan
2021-04-16  0:52 ` Florian Fainelli
2021-04-16  9:38 ` Naresh Kamboju
2021-04-16 19:57 ` Fox Chen
2021-04-16 20:07 ` Sudip Mukherjee
2021-04-17  1:01 ` Samuel Zou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210415144413.334856476@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=victor.liu@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).