media: i2c: ov08x40: Fix burst fill writing past the end of the range
Subsystems (4)
PATCH 1/1 media: i2c: ov08x40: Fix burst fill writing past the end of the range
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.
--- drivers/media/i2c/ov08x40.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/media/i2c/ov08x40.c +6 -4
@@ -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
Signature · 1 line
2.56.1