mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Lebedev <lsa.uz@pm.me>
To: Benjamin Mugnier <benjamin.mugnier@foss.st.com>,
	Sylvain Petinot <sylvain.petinot@foss.st.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: i2c: vd55g1: Bound the number of st,leds entries
Date: Mon, 09 Nov 2026 18:07:38 +0000	[thread overview]
Message-ID: <20261109180732.84703-1-lsa.uz@pm.me> (raw)

vd55g1_parse_dt_gpios() reads st,leds into a stack array of
VD55G1_NB_GPIOS entries, and vd55g1_parse_dt_gpios_array() reads as
many entries as the property has. The binding allows four, but nothing
checks that at run time, and on ACPI the property can come from a
software node or _DSD that no schema validates. A fifth entry is
written past the array.

Refuse more entries than the sensor has GPIOs.

Fixes: e56616d7b23c ("media: i2c: Add driver for ST VD55G1 camera sensor")
Signed-off-by: Sergey Lebedev <lsa.uz@pm.me>
---
Found while reviewing the vd55g0 driver, which has the same check.
There is no VD55G1 here, so this was tested with a module that runs
vd55g1_parse_dt_gpios_array(), copied unchanged, on a software node,
with a guard word after the four-entry array. Five st,leds entries
overwrite the guard and the call succeeds; with this patch it fails
with -EINVAL. Four entries parse as before.

Tool use, per Documentation/process/generated-content.rst (Assisted-by
tags in commits were dropped in 7.4-rc1):

* My contributions to this series were prepared with Claude Code
  (claude-opus-5-5); work by others in it is their own.
* This replaces any Assisted-by tags in earlier versions.

 drivers/media/i2c/vd55g1.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/vd55g1.c b/drivers/media/i2c/vd55g1.c
index e3939bb9bd4..2e847af3f1e 100644
--- a/drivers/media/i2c/vd55g1.c
+++ b/drivers/media/i2c/vd55g1.c
@@ -1854,6 +1854,11 @@ static int vd55g1_parse_dt_gpios_array(struct vd55g1 *sensor,
 		*nb = 0;
 		return 0;
 	}
+	if (*nb > VD55G1_NB_GPIOS) {
+		dev_err(sensor->dev, "%s lists %d GPIOs, the sensor has %d\n",
+			prop_name, *nb, VD55G1_NB_GPIOS);
+		return -EINVAL;
+	}
 
 	ret = device_property_read_u32_array(sensor->dev,
 					     prop_name, array, *nb);
-- 
2.54.0



                 reply	other threads:[~2026-11-09 18:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261109180732.84703-1-lsa.uz@pm.me \
    --to=lsa.uz@pm.me \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sylvain.petinot@foss.st.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

all inboxes | Powered by JetHome®