]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iio: light: cm3323: fix reg_conf not being initialized correctly
authorAldo Conte <aldocontelk@gmail.com>
Tue, 7 Apr 2026 15:17:01 +0000 (17:17 +0200)
committerJonathan Cameron <jic23@kernel.org>
Fri, 15 May 2026 11:01:38 +0000 (12:01 +0100)
commit1f4f0bcc5255dec5c4c3a1551bf49d8c33b69b20
tree36cf09e19ea04b9f8f1928fc6fa6dbd22f55e456
parent49f79cd28f1e3333cbe0d616ce59ead0b24bf34e
iio: light: cm3323: fix reg_conf not being initialized correctly

The code stores the return value of i2c_smbus_write_word_data()
in data->reg_conf; however, this value represents the result
of the write operation and not the value actually written to
the configuration register. This meant that the contents of
data->reg_conf did not truly reflect the contents
of the hardware register.

Instead, save the value of the register before the write
and use this value in the I2C write.

The bug was found by code inspection: i2c_smbus_write_word_data()
returns 0 on success, not the value written to the register.

Tested using i2c-stub on a Raspberry Pi 3B running a custom 6.19.10
kernel. Before loading the driver, the configuration register 0x00
CM3323_CMD_CONF was populated with 0x0030 using
`i2cset -y 11 0x10 0x00 0x0030 w`, encoding an integration time of 320ms
in bits[6:4].

Due to incorrect initialization of data->reg_conf in
cm3323_init(), the print of integration_time returns 0.040000
instead of the expected 0.320000. This happens because the read of the
integration_time depends on cm3323_get_it_bits() that is based on the
value of data->reg_conf, which is erroneously set to 0.

With this fix applied, data->reg_conf correctly saves 0x0030 after init
and the successive integration_time reports 0.320000 as expected.

Fixes: 8b0544263761 ("iio: light: Add support for Capella CM3323 color sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Conte <aldocontelk@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/light/cm3323.c