* [PATCH v2 0/2] iio: light: cm3323: fix and cleanup @ 2026-04-04 20:58 Aldo Conte 2026-04-04 20:58 ` [PATCH v2 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly Aldo Conte 2026-04-04 20:58 ` [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path Aldo Conte 0 siblings, 2 replies; 5+ messages in thread From: Aldo Conte @ 2026-04-04 20:58 UTC (permalink / raw) To: jic23 Cc: ktsai, dlechner, nuno.sa, andy, daniel.baluta, linux-iio, linux-kernel, skhan, me, linux-kernel-mentees This series fixes a bug and does a cleanup of the CM3323 color light sensor driver. Patch 1 fixes data->reg_conf being incorrectly initialized with the return value of the i2c_smbus_write_word_data() instead of the actual register value. Tested with i2c-stub on a Raspberri Pi 3B. Patch 2 converts dev_err() to dev_err_probe() in the probe path. Changes in v2: - Patch 1: fix typos in commit message - Patch 2: add struct device *dev to shorten dev_err_probe() calls to one-liners (suggested by Andy Shevchenko) Aldo Conte (2): iio: light: cm3323: fix reg_conf not being initialized correctly iio: light: cm3323: use dev_err_probe() in probe path drivers/iio/light/cm3323.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) -- 2.53.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly 2026-04-04 20:58 [PATCH v2 0/2] iio: light: cm3323: fix and cleanup Aldo Conte @ 2026-04-04 20:58 ` Aldo Conte 2026-04-04 20:58 ` [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path Aldo Conte 1 sibling, 0 replies; 5+ messages in thread From: Aldo Conte @ 2026-04-04 20:58 UTC (permalink / raw) To: jic23 Cc: ktsai, dlechner, nuno.sa, andy, daniel.baluta, linux-iio, linux-kernel, skhan, me, linux-kernel-mentees 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> --- Changes in v2: - fix typos in commit message drivers/iio/light/cm3323.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c index 79ad6e2209ca..0fe61b8a7029 100644 --- a/drivers/iio/light/cm3323.c +++ b/drivers/iio/light/cm3323.c @@ -89,15 +89,14 @@ static int cm3323_init(struct iio_dev *indio_dev) /* enable sensor and set auto force mode */ ret &= ~(CM3323_CONF_SD_BIT | CM3323_CONF_AF_BIT); + data->reg_conf = ret; - ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, ret); + ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, data->reg_conf); if (ret < 0) { dev_err(&data->client->dev, "Error writing reg_conf\n"); return ret; } - data->reg_conf = ret; - return 0; } -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path 2026-04-04 20:58 [PATCH v2 0/2] iio: light: cm3323: fix and cleanup Aldo Conte 2026-04-04 20:58 ` [PATCH v2 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly Aldo Conte @ 2026-04-04 20:58 ` Aldo Conte 2026-04-05 15:12 ` David Lechner 2026-04-06 17:24 ` Andy Shevchenko 1 sibling, 2 replies; 5+ messages in thread From: Aldo Conte @ 2026-04-04 20:58 UTC (permalink / raw) To: jic23 Cc: ktsai, dlechner, nuno.sa, andy, daniel.baluta, linux-iio, linux-kernel, skhan, me, linux-kernel-mentees Replace dev_err() calls with dev_err_probe() in cm3323_init() and cm3323_probe(). cm3323_init() is called by cm3323_probe(), so using dev_err_probe() ensures that deferred probing is handled correctly and simplifies error paths. Remove the redundant error message in cm3323_probe(). Tested on a Raspberry Pi 3B using i2c-stub. The driver probes successfully and successfully read integration_time after this change. Suggested-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Aldo Conte <aldocontelk@gmail.com> --- Changes in v2: - Add struct device *dev local variable to shorten dev_err_probe() calls to one-liners (suggested by Andy Shevchenko) drivers/iio/light/cm3323.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c index 0fe61b8a7029..5b36fc265c6c 100644 --- a/drivers/iio/light/cm3323.c +++ b/drivers/iio/light/cm3323.c @@ -80,22 +80,19 @@ static int cm3323_init(struct iio_dev *indio_dev) { int ret; struct cm3323_data *data = iio_priv(indio_dev); + struct device *dev = &data->client->dev; ret = i2c_smbus_read_word_data(data->client, CM3323_CMD_CONF); - if (ret < 0) { - dev_err(&data->client->dev, "Error reading reg_conf\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Error reading reg_conf\n"); /* enable sensor and set auto force mode */ ret &= ~(CM3323_CONF_SD_BIT | CM3323_CONF_AF_BIT); data->reg_conf = ret; ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, data->reg_conf); - if (ret < 0) { - dev_err(&data->client->dev, "Error writing reg_conf\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Error writing reg_conf\n"); return 0; } @@ -236,10 +233,9 @@ static int cm3323_probe(struct i2c_client *client) indio_dev->modes = INDIO_DIRECT_MODE; ret = cm3323_init(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "cm3323 chip init failed\n"); + if (ret < 0) return ret; - } + ret = devm_add_action_or_reset(&client->dev, cm3323_disable, indio_dev); if (ret < 0) -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path 2026-04-04 20:58 ` [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path Aldo Conte @ 2026-04-05 15:12 ` David Lechner 2026-04-06 17:24 ` Andy Shevchenko 1 sibling, 0 replies; 5+ messages in thread From: David Lechner @ 2026-04-05 15:12 UTC (permalink / raw) To: Aldo Conte, jic23 Cc: ktsai, nuno.sa, andy, daniel.baluta, linux-iio, linux-kernel, skhan, me, linux-kernel-mentees On 4/4/26 3:58 PM, Aldo Conte wrote: > Replace dev_err() calls with dev_err_probe() in cm3323_init() and > cm3323_probe(). cm3323_init() is called by cm3323_probe(), so using > dev_err_probe() ensures that deferred probing is handled > correctly and simplifies error paths. > > Remove the redundant error message in cm3323_probe(). > > Tested on a Raspberry Pi 3B using i2c-stub. The driver probes > successfully and successfully read integration_time after this change. > > Suggested-by: Andy Shevchenko <andy@kernel.org> > Signed-off-by: Aldo Conte <aldocontelk@gmail.com> > --- > Changes in v2: > - Add struct device *dev local variable to shorten dev_err_probe() > calls to one-liners (suggested by Andy Shevchenko) > > drivers/iio/light/cm3323.c | 18 +++++++----------- > 1 file changed, 7 insertions(+), 11 deletions(-) > > diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c > index 0fe61b8a7029..5b36fc265c6c 100644 > --- a/drivers/iio/light/cm3323.c > +++ b/drivers/iio/light/cm3323.c > @@ -80,22 +80,19 @@ static int cm3323_init(struct iio_dev *indio_dev) > { > int ret; > struct cm3323_data *data = iio_priv(indio_dev); > + struct device *dev = &data->client->dev; > > ret = i2c_smbus_read_word_data(data->client, CM3323_CMD_CONF); > - if (ret < 0) { > - dev_err(&data->client->dev, "Error reading reg_conf\n"); > - return ret; > - } > + if (ret < 0) > + return dev_err_probe(dev, ret, "Error reading reg_conf\n"); > > /* enable sensor and set auto force mode */ > ret &= ~(CM3323_CONF_SD_BIT | CM3323_CONF_AF_BIT); > data->reg_conf = ret; > > ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, data->reg_conf); > - if (ret < 0) { > - dev_err(&data->client->dev, "Error writing reg_conf\n"); > - return ret; > - } > + if (ret < 0) > + return dev_err_probe(dev, ret, "Error writing reg_conf\n"); > > return 0; > } > @@ -236,10 +233,9 @@ static int cm3323_probe(struct i2c_client *client) > indio_dev->modes = INDIO_DIRECT_MODE; > > ret = cm3323_init(indio_dev); > - if (ret < 0) { > - dev_err(&client->dev, "cm3323 chip init failed\n"); > + if (ret < 0) > return ret; > - } > + > checkpatch.pl should have warned about having to blank lines here now. Prefer only one. > ret = devm_add_action_or_reset(&client->dev, cm3323_disable, indio_dev); > if (ret < 0) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path 2026-04-04 20:58 ` [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path Aldo Conte 2026-04-05 15:12 ` David Lechner @ 2026-04-06 17:24 ` Andy Shevchenko 1 sibling, 0 replies; 5+ messages in thread From: Andy Shevchenko @ 2026-04-06 17:24 UTC (permalink / raw) To: Aldo Conte Cc: jic23, ktsai, dlechner, nuno.sa, andy, daniel.baluta, linux-iio, linux-kernel, skhan, me, linux-kernel-mentees On Sat, Apr 04, 2026 at 10:58:52PM +0200, Aldo Conte wrote: > Replace dev_err() calls with dev_err_probe() in cm3323_init() and > cm3323_probe(). cm3323_init() is called by cm3323_probe(), so using > dev_err_probe() ensures that deferred probing is handled > correctly and simplifies error paths. > > Remove the redundant error message in cm3323_probe(). > > Tested on a Raspberry Pi 3B using i2c-stub. The driver probes > successfully and successfully read integration_time after this change. Reviewed-by: Andy Shevchenko <andy@kernel.org> assuming the comment from David is being addressed. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-06 17:24 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-04 20:58 [PATCH v2 0/2] iio: light: cm3323: fix and cleanup Aldo Conte 2026-04-04 20:58 ` [PATCH v2 1/2] iio: light: cm3323: fix reg_conf not being initialized correctly Aldo Conte 2026-04-04 20:58 ` [PATCH v2 2/2] iio: light: cm3323: use dev_err_probe() in probe path Aldo Conte 2026-04-05 15:12 ` David Lechner 2026-04-06 17:24 ` Andy Shevchenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox