mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valentin Allemand <valentin.allmnd@gmail.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Jimmy Su <jimmy.su@intel.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@kernel.org>,
	Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	Valentin Allemand <valentin.allmnd@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] media: i2c: ov08x40: Fix burst fill writing past the end of the range
Date: Mon, 23 Nov 2026 17:19:10 +0100	[thread overview]
Message-ID: <20261123161910.31956-1-valentin.allmnd@gmail.com> (raw)

ov08x40_burst_fill_regs() sets the length of each write to the
adapter's max_write_len - 2 without clamping it to the number of
registers left to fill. Whenever the requested range is not a multiple
of that length, the last write runs past last_reg.

The burst fill is used for the two cross-talk tables (0x5a80-0x5b9f,
288 registers, and 0x5bc0-0x5f1f, 864 registers) after the mode
register list has been written. With i2c-usbio (max_write_len 4096)
each table is filled by a single 4094-byte write, which overwrites
thousands of registers past the end of the table with the fill value,
including registers set earlier by the mode list. This shows up as a
fine 4x4 pixel grid and blocky patches in the image. With an adapter
limited to 52 bytes, the last write of each table still overruns by
12 and 36 registers respectively.

Clamp each write to the number of registers left to fill, and loop
until all of them have been written.

Fixes: d0fef6de4f1b ("media: ov08x40: Fix burst write sequence")
Cc: stable@vger.kernel.org
Signed-off-by: Valentin Allemand <valentin.allmnd@gmail.com>
---
 drivers/media/i2c/ov08x40.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov08x40.c b/drivers/media/i2c/ov08x40.c
index df2c63d64e62..4ddb202d5c32 100644
--- a/drivers/media/i2c/ov08x40.c
+++ b/drivers/media/i2c/ov08x40.c
@@ -1461,22 +1461,24 @@ static int ov08x40_burst_fill_regs(struct ov08x40 *ov08x, u16 first_reg,
 				   u16 last_reg,  u8 val)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&ov08x->sd);
-	size_t num_regs, num_write_regs;
+	size_t num_regs, max_write_regs, num_write_regs;
 	int ret;
 
 	num_regs = last_reg - first_reg + 1;
-	num_write_regs = num_regs;
+	max_write_regs = num_regs;
 
 	if (client->adapter->quirks && client->adapter->quirks->max_write_len)
-		num_write_regs = client->adapter->quirks->max_write_len - 2;
+		max_write_regs = client->adapter->quirks->max_write_len - 2;
 
-	while (first_reg < last_reg) {
+	while (num_regs) {
+		num_write_regs = min(num_regs, max_write_regs);
 		ret = __ov08x40_burst_fill_regs(client, first_reg, last_reg,
 						num_write_regs, val);
 		if (ret)
 			return ret;
 
 		first_reg += num_write_regs;
+		num_regs -= num_write_regs;
 	}
 
 	return 0;

base-commit: b7ac871daee981f1963f632586ff9b9d898ce5dd
-- 
2.56.1


                 reply	other threads:[~2026-11-23 16:19 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=20261123161910.31956-1-valentin.allmnd@gmail.com \
    --to=valentin.allmnd@gmail.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=hverkuil@kernel.org \
    --cc=jimmy.su@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /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®