Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] media: i2c: ov08x40: Fix burst fill writing past the end of the range
@ 2026-11-23 16:19 Valentin Allemand
  0 siblings, 0 replies; only message in thread
From: Valentin Allemand @ 2026-11-23 16:19 UTC (permalink / raw)
  To: Sakari Ailus, Jimmy Su
  Cc: linux-media, linux-kernel, Mauro Carvalho Chehab, Hans Verkuil,
	Bryan O'Donoghue, Valentin Allemand, stable

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 16:19 [PATCH] media: i2c: ov08x40: Fix burst fill writing past the end of the range Valentin Allemand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox