The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 00/12] ROHM IIO fixes
@ 2026-08-10  7:49 Matti Vaittinen
  2026-08-10  7:49 ` [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm Matti Vaittinen
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:49 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]

Fix a few issues from IIO drivers for ROHM components.

I hired couple of gnomes to work for me. :) (Ran AI reviews).
Unsurprizingly some bugs were spotted. Time to try fix mess (mostly) I
have authored.

Bugs were found by AI review but fixes are made by hand. Hence no
AI-tooling tags are added. Please, let me know if one is needed.

---

NOTE: Only _very_ shallow testing is done. Some of the fixes are not
tested in the hardware at all. All reviewing and testing is appreciated
as usual!

Matti Vaittinen (12):
  iio: adc: rohm-bd79124: Fix rising alarm
  iio: adc: rohm-bd79124: Fix channel initialization
  iio: adc: rohm-bd79124: Fix GPIO mask check
  iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop
  iio: dac: rohm-bd79703: Do not allow writing SCALE
  iio: pressure: rohm-bm1390: Return error when read fails
  iio: pressure: rohm-bm1390: Fix AVE_NUM initialization
  iio: light: rohm-bu27034: Fix error return
  iio: light: rohm-bu27034: Fix infinite delay on error
  iio: accel: kionix-kx022a: Fix array boundary check
  iio: accel: kionix-kx022a: Prevent memory leak and fix state
  iio: accel: kionix-kx022a: Fix IPOL macro name

 drivers/iio/accel/kionix-kx022a.c  | 29 +++++++++++++++++++++++------
 drivers/iio/accel/kionix-kx022a.h  |  2 +-
 drivers/iio/adc/rohm-bd79124.c     | 20 ++++++++++++++------
 drivers/iio/dac/rohm-bd79703.c     |  3 +++
 drivers/iio/light/rohm-bu27034.c   | 12 +++++++++++-
 drivers/iio/pressure/rohm-bm1390.c |  6 ++++--
 6 files changed, 56 insertions(+), 16 deletions(-)


base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
@ 2026-08-10  7:49 ` Matti Vaittinen
  2026-08-10  7:50 ` [PATCH 02/12] iio: adc: rohm-bd79124: Fix channel initialization Matti Vaittinen
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:49 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The rising alarm is using the cached falling alarm value causing wrong
value to be used.

Fix this by using the correct cached value for rising alarm.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 3f57a3b9ab74 ("iio: adc: Support ROHM BD79124 ADC")
---
 drivers/iio/adc/rohm-bd79124.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/rohm-bd79124.c b/drivers/iio/adc/rohm-bd79124.c
index 864f3b1366b5..f703c74309cc 100644
--- a/drivers/iio/adc/rohm-bd79124.c
+++ b/drivers/iio/adc/rohm-bd79124.c
@@ -525,7 +525,7 @@ static int bd79124_enable_event(struct bd79124_data *data,
 		return ret;
 
 	if (dir == IIO_EV_DIR_RISING) {
-		limit = &data->alarm_f_limit[channel];
+		limit = &data->alarm_r_limit[channel];
 		reg = BD79124_GET_HIGH_LIMIT_REG(channel);
 	} else {
 		limit = &data->alarm_f_limit[channel];
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/12] iio: adc: rohm-bd79124: Fix channel initialization
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
  2026-08-10  7:49 ` [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm Matti Vaittinen
@ 2026-08-10  7:50 ` Matti Vaittinen
  2026-08-10  7:50 ` [PATCH 03/12] iio: adc: rohm-bd79124: Fix GPIO mask check Matti Vaittinen
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:50 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1579 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The alarm limit register on BD79124 span to two consecutive registers.
The first register for high-limit containing also hysteresis
configuration. The initialization in driver writes only one 8-bit
register, overwriting the hysteresis and leaving the other limit
register uninitialized.

Fix the limit initialization by using the bd79124_write_int_to_reg(),
which correctly initializes the limit on both of the registers.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 3f57a3b9ab74 ("iio: adc: Support ROHM BD79124 ADC")
---
 drivers/iio/adc/rohm-bd79124.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/rohm-bd79124.c b/drivers/iio/adc/rohm-bd79124.c
index f703c74309cc..72207e0c60b8 100644
--- a/drivers/iio/adc/rohm-bd79124.c
+++ b/drivers/iio/adc/rohm-bd79124.c
@@ -920,13 +920,13 @@ static int bd79124_chan_init(struct bd79124_data *data, int channel)
 {
 	int ret;
 
-	ret = regmap_write(data->map, BD79124_GET_HIGH_LIMIT_REG(channel),
-			   BD79124_HIGH_LIMIT_MAX);
+	ret = bd79124_write_int_to_reg(data, BD79124_GET_HIGH_LIMIT_REG(channel),
+				       BD79124_HIGH_LIMIT_MAX);
 	if (ret)
 		return ret;
 
-	return regmap_write(data->map, BD79124_GET_LOW_LIMIT_REG(channel),
-			    BD79124_LOW_LIMIT_MIN);
+	return bd79124_write_int_to_reg(data, BD79124_GET_LOW_LIMIT_REG(channel),
+					BD79124_LOW_LIMIT_MIN);
 }
 
 static int bd79124_get_gpio_pins(const struct iio_chan_spec *cs, int num_channels)
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/12] iio: adc: rohm-bd79124: Fix GPIO mask check
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
  2026-08-10  7:49 ` [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm Matti Vaittinen
  2026-08-10  7:50 ` [PATCH 02/12] iio: adc: rohm-bd79124: Fix channel initialization Matti Vaittinen
@ 2026-08-10  7:50 ` Matti Vaittinen
  2026-08-10  7:51 ` [PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop Matti Vaittinen
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:50 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1266 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The ROHM BD79124 has pins which can be configured as GPOs or as ADC
inputs. The bd79124gpo_set_multiple() is intended to ensure that a pin
which is requested to be toggled, is indeed configured as a GPO.

The check uses XOR, causing it to fail if mask is not exactly same as
GPO configuration. Eg, if not all GPOs are asked to be toggled at once.

Fix this by checking that mask does not contain pins that are not
configured as GPO, allowing some of the pins which are configured as
GPO to be untouched.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 3f57a3b9ab74 ("iio: adc: Support ROHM BD79124 ADC")
---
 drivers/iio/adc/rohm-bd79124.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/rohm-bd79124.c b/drivers/iio/adc/rohm-bd79124.c
index 72207e0c60b8..84ac7fc94581 100644
--- a/drivers/iio/adc/rohm-bd79124.c
+++ b/drivers/iio/adc/rohm-bd79124.c
@@ -201,7 +201,7 @@ static int bd79124gpo_set_multiple(struct gpio_chip *gc, unsigned long *mask,
 	if (ret)
 		return ret;
 
-	if (all_gpos ^ *mask) {
+	if (*mask & ~all_gpos) {
 		dev_dbg(data->dev, "Invalid mux config. Can't set value.\n");
 
 		return -EINVAL;
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (2 preceding siblings ...)
  2026-08-10  7:50 ` [PATCH 03/12] iio: adc: rohm-bd79124: Fix GPIO mask check Matti Vaittinen
@ 2026-08-10  7:51 ` Matti Vaittinen
  2026-08-10  7:51 ` [PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE Matti Vaittinen
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:51 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1713 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The bd79124_start_measurement() and bd79124_stop_measurement() ignore
errors from the regmap reads, causing potential use of uninitialized
stack variable when deciding whether the measurement is already
started/stopped. The bd79124_stop_measurement() may also ignore failure
to clear the sequencer state bits, which may make the hardware to ignore
the setting and leave hardware and driver states out of sync.

Check the return value and bail-out if error is detected.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 3f57a3b9ab74 ("iio: adc: Support ROHM BD79124 ADC")
---
 drivers/iio/adc/rohm-bd79124.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/adc/rohm-bd79124.c b/drivers/iio/adc/rohm-bd79124.c
index 84ac7fc94581..600354fe0ee0 100644
--- a/drivers/iio/adc/rohm-bd79124.c
+++ b/drivers/iio/adc/rohm-bd79124.c
@@ -382,6 +382,9 @@ static int bd79124_start_measurement(struct bd79124_data *data, int chan)
 
 	/* See if already started */
 	ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &val);
+	if (ret)
+		return ret;
+
 	if (val & BIT(chan))
 		return 0;
 
@@ -421,11 +424,16 @@ static int bd79124_stop_measurement(struct bd79124_data *data, int chan)
 
 	/* See if already stopped */
 	ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &enabled_chans);
+	if (ret)
+		return ret;
+
 	if (!(enabled_chans & BIT(chan)))
 		return 0;
 
 	ret = regmap_clear_bits(data->map, BD79124_REG_SEQ_CFG,
 				BD79124_MSK_SEQ_START);
+	if (ret)
+		return ret;
 
 	/* Clear the channel from the measured channels */
 	enabled_chans &= ~BIT(chan);
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (3 preceding siblings ...)
  2026-08-10  7:51 ` [PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop Matti Vaittinen
@ 2026-08-10  7:51 ` Matti Vaittinen
  2026-08-10  7:52 ` [PATCH 06/12] iio: pressure: rohm-bm1390: Return error when read fails Matti Vaittinen
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:51 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The BD79703 has adds IIO_CHAN_INFO_SCALE in the info_mask_shared_by_type
so users can read the scale, which depends on the used reference
voltage. This, however, enables users to try writing the scale as well.
This isn't really supported but the bd79703_write_raw() does not check
the mask, and if written scale values pass the validation, the driver
will proceed writing the DAC value when users writes the scale.

Prevent the unsupported scale setting and return an error.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: af6aca656a85 ("iio: dac: Support ROHM BD79703 DAC")
---
 drivers/iio/dac/rohm-bd79703.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/dac/rohm-bd79703.c b/drivers/iio/dac/rohm-bd79703.c
index e91090e4a66d..68e66e7286d8 100644
--- a/drivers/iio/dac/rohm-bd79703.c
+++ b/drivers/iio/dac/rohm-bd79703.c
@@ -73,6 +73,9 @@ static int bd79703_write_raw(struct iio_dev *idev,
 {
 	struct bd79703_data *data = iio_priv(idev);
 
+	if (mask != IIO_CHAN_INFO_RAW)
+		return -EINVAL;
+
 	if (val < 0 || val >= 1 << BD79703_DAC_BITS)
 		return -EINVAL;
 
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/12] iio: pressure: rohm-bm1390: Return error when read fails
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (4 preceding siblings ...)
  2026-08-10  7:51 ` [PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE Matti Vaittinen
@ 2026-08-10  7:52 ` Matti Vaittinen
  2026-08-10  7:53 ` [PATCH 07/12] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization Matti Vaittinen
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:52 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The data reading function ignores the cached error value, and
unconditionally returns 0. Return cached 'ret' -value after stopping
the measurement so user knows if read failed and data is garbage.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 534674463a59 ("iio: bm1390: simplify using guard(mutex)")
---
 drivers/iio/pressure/rohm-bm1390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
index b3be9de03678..d00d7ed54cb1 100644
--- a/drivers/iio/pressure/rohm-bm1390.c
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -289,7 +289,7 @@ static int bm1390_read_data(struct bm1390_data *data,
 	if (warn)
 		dev_warn(data->dev, "Failed to stop measurement (%d)\n", warn);
 
-	return 0;
+	return ret;
 }
 
 static int bm1390_read_raw(struct iio_dev *idev,
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/12] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (5 preceding siblings ...)
  2026-08-10  7:52 ` [PATCH 06/12] iio: pressure: rohm-bm1390: Return error when read fails Matti Vaittinen
@ 2026-08-10  7:53 ` Matti Vaittinen
  2026-08-10  7:53 ` [PATCH 08/12] iio: light: rohm-bu27034: Fix error return Matti Vaittinen
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:53 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The BM1390 tries to initialize the AVE_NUM to 110b at the start-up. The
field location is not taken into account, and value is written unsifted.
This causes the AVE_NUM to be initialized to zero.

Use FIELD_PREP() to shift the intended AVE_NUM value to correct field.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 81ca5979b6ed ("iio: pressure: Support ROHM BU1390")
---
 drivers/iio/pressure/rohm-bm1390.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/rohm-bm1390.c b/drivers/iio/pressure/rohm-bm1390.c
index d00d7ed54cb1..29454570f257 100644
--- a/drivers/iio/pressure/rohm-bm1390.c
+++ b/drivers/iio/pressure/rohm-bm1390.c
@@ -479,6 +479,7 @@ static const struct iio_info bm1390_info = {
 
 static int bm1390_chip_init(struct bm1390_data *data)
 {
+	u8 regval;
 	int ret;
 
 	ret = regmap_write_bits(data->regmap, BM1390_REG_POWER,
@@ -512,8 +513,9 @@ static int bm1390_chip_init(struct bm1390_data *data)
 	 * Default to use IIR filter in "middle" mode. Also the AVE_NUM must
 	 * be fixed when IIR is in use.
 	 */
+	regval = FIELD_PREP(BM1390_MASK_AVE_NUM, BM1390_IIR_AVE_NUM);
 	ret = regmap_update_bits(data->regmap, BM1390_REG_MODE_CTRL,
-				 BM1390_MASK_AVE_NUM, BM1390_IIR_AVE_NUM);
+				 BM1390_MASK_AVE_NUM, regval);
 	if (ret)
 		return ret;
 
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/12] iio: light: rohm-bu27034: Fix error return
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (6 preceding siblings ...)
  2026-08-10  7:53 ` [PATCH 07/12] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization Matti Vaittinen
@ 2026-08-10  7:53 ` Matti Vaittinen
  2026-08-10  7:54 ` [PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error Matti Vaittinen
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:53 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

When BU27034 fails to read gain value at integration-time setting, it
returns 0. This leaves caller unaware of the fact that setting the
integration time failed.

Fix this by returning the relevant error instead of zero.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 439c2cef8157 ("iio: bu27034: simplify using guard(mutex)")
---
 drivers/iio/light/rohm-bu27034.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
index 28d111ac8c0a..f9a421618406 100644
--- a/drivers/iio/light/rohm-bu27034.c
+++ b/drivers/iio/light/rohm-bu27034.c
@@ -415,7 +415,7 @@ static int bu27034_try_set_int_time(struct bu27034_data *data, int time_us)
 	for (i = 0; i < numg; i++) {
 		ret = bu27034_get_gain(data, gains[i].chan, &gains[i].old_gain);
 		if (ret)
-			return 0;
+			return ret;
 
 		ret = iio_gts_find_new_gain_by_old_gain_time(&data->gts,
 							     gains[i].old_gain,
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (7 preceding siblings ...)
  2026-08-10  7:53 ` [PATCH 08/12] iio: light: rohm-bu27034: Fix error return Matti Vaittinen
@ 2026-08-10  7:54 ` Matti Vaittinen
  2026-08-10  7:54 ` [PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check Matti Vaittinen
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:54 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

When reading an integration-time fails, the code will use error code to
compute the sleep time.

Fix this by using the smallest integration time as a default if
reading fails.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor")
---
 drivers/iio/light/rohm-bu27034.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c
index f9a421618406..e6efb8adfe37 100644
--- a/drivers/iio/light/rohm-bu27034.c
+++ b/drivers/iio/light/rohm-bu27034.c
@@ -137,6 +137,7 @@ static const struct iio_gain_sel_pair bu27034_gains[] = {
 #define BU27034_MEAS_MODE_200MS		2
 #define BU27034_MEAS_MODE_400MS		4
 
+#define BU27034_INT_TIME_MIN 55000
 static const struct iio_itime_sel_mul bu27034_itimes[] = {
 	GAIN_SCALE_ITIME_US(400000, BU27034_MEAS_MODE_400MS, 8),
 	GAIN_SCALE_ITIME_US(200000, BU27034_MEAS_MODE_200MS, 4),
@@ -1162,6 +1163,15 @@ static int bu27034_buffer_thread(void *arg)
 	data = iio_priv(idev);
 
 	wait_ms = bu27034_get_int_time(data);
+
+	/*
+	 * If reading the integration time fails, default to the minimum so we
+	 * don't lose samples. This may waste CPU cycles, but as a hardening
+	 * against theoretical, once-in-a-blue-moon error, this should be Ok.
+	 */
+	if (wait_ms < 0)
+		wait_ms = BU27034_INT_TIME_MIN;
+
 	wait_ms /= 1000;
 
 	wait_ms -= BU27034_MEAS_WAIT_PREMATURE_MS;
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (8 preceding siblings ...)
  2026-08-10  7:54 ` [PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error Matti Vaittinen
@ 2026-08-10  7:54 ` Matti Vaittinen
  2026-08-10  7:55 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state Matti Vaittinen
  2026-08-10  7:55 ` [PATCH 12/12] iio: accel: kionix-kx022a: Fix IPOL macro name Matti Vaittinen
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:54 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The driver performs a sanity check for an array size, when converting a
register value to an array index. The check incorrectly accepts the
sizeof(array) as a last index, when last valid index should be
sizeof(array) - 1.

Fix the check by bailing out when index >= sizeof(array).

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 7c1d1677b322 ("iio: accel: Support Kionix/ROHM KX022A accelerometer")
---
 drivers/iio/accel/kionix-kx022a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 39485572a76b..8a13f78aeab0 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -649,7 +649,7 @@ static int kx022a_read_raw(struct iio_dev *idev,
 		if (ret)
 			return ret;
 
-		if ((regval & KX022A_MASK_ODR) >
+		if ((regval & KX022A_MASK_ODR) >=
 		    ARRAY_SIZE(kx022a_accel_samp_freq_table)) {
 			dev_err(data->dev, "Invalid ODR\n");
 			return -EINVAL;
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (9 preceding siblings ...)
  2026-08-10  7:54 ` [PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check Matti Vaittinen
@ 2026-08-10  7:55 ` Matti Vaittinen
  2026-08-10  7:55 ` [PATCH 12/12] iio: accel: kionix-kx022a: Fix IPOL macro name Matti Vaittinen
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:55 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 2227 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The driver allocates memory for samples at buffer enable path. If regmap
operation fails in the kx022a_fifo_enable() at the buffer enable path, the
allocated memory is never freed. Furthermore, the state information and
previous hardware configuration(s) aren't undone, potentially leaving
WMI interrupts and buffers enabled, or driver state flags wrong.

Free the memory and revert the hardware configuration and state flags on
error path.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: e7123a4dfcd7 ("iio: accel: kionix-kx022a: Refactor driver and add chip_info structure")
---
 drivers/iio/accel/kionix-kx022a.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 8a13f78aeab0..49e8b4b943da 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -980,26 +980,43 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
 	guard(mutex)(&data->mutex);
 	ret = __kx022a_turn_on_off(data, false);
 	if (ret)
-		return ret;
+		goto err_free_out;
 
 	/* Update watermark to HW */
 	ret = kx022a_fifo_set_wmi(data);
 	if (ret)
-		return ret;
+		goto err_free_out;
 
 	/* Enable buffer */
 	ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
 			      KX022A_MASK_BUF_EN);
 	if (ret)
-		return ret;
+		goto err_free_out;
 
 	data->state |= KX022A_STATE_FIFO;
 	ret = regmap_set_bits(data->regmap, data->ien_reg,
 			      KX022A_MASK_WMI);
 	if (ret)
-		return ret;
+		goto err_wmi_out;
 
-	return __kx022a_turn_on_off(data, true);
+	ret = __kx022a_turn_on_off(data, true);
+	if (ret)
+		goto err_on_out;
+
+	return ret;
+
+err_on_out:
+	regmap_clear_bits(data->regmap, data->ien_reg,
+			  KX022A_MASK_WMI);
+err_wmi_out:
+	regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
+			  KX022A_MASK_BUF_EN);
+err_free_out:
+	kfree(data->fifo_buffer);
+	data->state &= ~KX022A_STATE_FIFO;
+	__kx022a_turn_on_off(data, true);
+
+	return ret;
 }
 
 static int kx022a_buffer_postenable(struct iio_dev *idev)
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 12/12] iio: accel: kionix-kx022a: Fix IPOL macro name
  2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
                   ` (10 preceding siblings ...)
  2026-08-10  7:55 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state Matti Vaittinen
@ 2026-08-10  7:55 ` Matti Vaittinen
  11 siblings, 0 replies; 13+ messages in thread
From: Matti Vaittinen @ 2026-08-10  7:55 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen, Matti Vaittinen,
	0012-iio-accel-kx022a-Fix-IPOL-macro-name.patch
  Cc: Matti Vaittinen, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Javier Carrasco, Mehdi Djait, linux-iio,
	linux-kernel, Kalle Niemi, Topi Sonkajärvi

[-- Attachment #1: Type: text/plain, Size: 1583 bytes --]

From: Matti Vaittinen <mazziesaccount@gmail.com>

The "interrupt polarity high" -macro for KX022A variant is defined as:
However, the KX022A_MASK_IPOL1 is not defined anywhere, so actually
using the KX022A_IPOL_HIGH would produce a compile error.

Fix the define by using correct mask.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 7c1d1677b322 ("iio: accel: Support Kionix/ROHM KX022A accelerometer")

---
It appears the KX022A_IPOL_HIGH is unused as the IRQ is currently,
unconditionally set level low in kx022a_prepare_irq_pin(). The KX022A
hardware would support other configurations though. So, another
potential fix would be removing the define altogether. I decided to
leave the define there, as having it will allow users who need different
configuration to simply change the KX022A_IPOL_LOW to KX022A_IPOL_HIGH,
which is kind of a "easy to try" thing.

I don't have a strong preference here though.
---
 drivers/iio/accel/kionix-kx022a.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
index 0ed54f584223..a2d122c1e234 100644
--- a/drivers/iio/accel/kionix-kx022a.h
+++ b/drivers/iio/accel/kionix-kx022a.h
@@ -65,7 +65,7 @@
 #define KX022A_MASK_IEN		BIT(5)
 #define KX022A_MASK_IPOL	BIT(4)
 #define KX022A_IPOL_LOW		0
-#define KX022A_IPOL_HIGH	KX022A_MASK_IPOL1
+#define KX022A_IPOL_HIGH	KX022A_MASK_IPOL
 #define KX022A_MASK_ITYP	BIT(3)
 #define KX022A_ITYP_PULSE	KX022A_MASK_ITYP
 #define KX022A_ITYP_LEVEL	0
-- 
2.55.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-08-10  7:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10  7:49 [PATCH 00/12] ROHM IIO fixes Matti Vaittinen
2026-08-10  7:49 ` [PATCH 01/12] iio: adc: rohm-bd79124: Fix rising alarm Matti Vaittinen
2026-08-10  7:50 ` [PATCH 02/12] iio: adc: rohm-bd79124: Fix channel initialization Matti Vaittinen
2026-08-10  7:50 ` [PATCH 03/12] iio: adc: rohm-bd79124: Fix GPIO mask check Matti Vaittinen
2026-08-10  7:51 ` [PATCH 04/12] iio: adc: rohm-bd79124: Catch regmap errors at measurement start/stop Matti Vaittinen
2026-08-10  7:51 ` [PATCH 05/12] iio: dac: rohm-bd79703: Do not allow writing SCALE Matti Vaittinen
2026-08-10  7:52 ` [PATCH 06/12] iio: pressure: rohm-bm1390: Return error when read fails Matti Vaittinen
2026-08-10  7:53 ` [PATCH 07/12] iio: pressure: rohm-bm1390: Fix AVE_NUM initialization Matti Vaittinen
2026-08-10  7:53 ` [PATCH 08/12] iio: light: rohm-bu27034: Fix error return Matti Vaittinen
2026-08-10  7:54 ` [PATCH 09/12] iio: light: rohm-bu27034: Fix infinite delay on error Matti Vaittinen
2026-08-10  7:54 ` [PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check Matti Vaittinen
2026-08-10  7:55 ` [PATCH 11/12] iio: accel: kionix-kx022a: Prevent memory leak and fix state Matti Vaittinen
2026-08-10  7:55 ` [PATCH 12/12] iio: accel: kionix-kx022a: Fix IPOL macro name Matti Vaittinen

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