media: dw2102: Don't translate i2c read into write
authorMichael Bunk <micha@freedict.org>
Sun, 16 Jan 2022 11:22:36 +0000 (11:22 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Mon, 29 Apr 2024 08:21:50 +0000 (09:21 +0100)
commit0e148a522b8453115038193e19ec7bea71403e4a
treedd77a45eb230c68a2b00461bc6cb06b64698aef8
parentc6ad2b9218d6d9538f60040ad12621ecb1274a0f
media: dw2102: Don't translate i2c read into write

The code ignored the I2C_M_RD flag on I2C messages.  Instead it assumed
an i2c transaction with a single message must be a write operation and a
transaction with two messages would be a read operation.

Though this works for the driver code, it leads to problems once the i2c
device is exposed to code not knowing this convention.  For example,
I did "insmod i2c-dev" and issued read requests from userspace, which
were translated into write requests and destroyed the EEPROM of my
device.

So, just check and respect the I2C_M_READ flag, which indicates a read
when set on a message.  If it is absent, it is a write message.

Incidentally, changing from the case statement to a while loop allows
the code to lift the limitation to two i2c messages per transaction.

There are 4 more *_i2c_transfer functions affected by the same behaviour
and limitation that should be fixed in the same way.

Link: https://lore.kernel.org/linux-media/20220116112238.74171-2-micha@freedict.org
Signed-off-by: Michael Bunk <micha@freedict.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/usb/dvb-usb/dw2102.c