The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: light: opt4060: Fix integration time, pointer type and error message
@ 2026-07-15  1:15 Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 1/3] iio: light: opt4060: Reject integration times with a non-zero seconds part Vidhu Sarwal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vidhu Sarwal @ 2026-07-15  1:15 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Per-Daniel Olsson,
	linux-iio, linux-kernel, skhan, linux-kernel-mentees,
	Vidhu Sarwal

This series fixes three issues in the opt4060 driver, all of which have
been present since the driver was introduced.

Patch 1 rejects integration time writes with a non-zero seconds part.
Previously, opt4060_write_raw() only considered the microseconds
component, so values such as 1.000600 were accepted and programmed as
600 us.

Patch 2 fixes a pointer type mismatch in the call to
div_u64_rem(). This is a type cleanliness fix and does not change
runtime behaviour.

Patch 3 corrects a error in an error message that reported the
wrong threshold register when a register read failed.

The first 2 patches are similar to recently submitted patches on
it's sister driver OPT4001 [1]. 

Patch 3 is specific to opt4060.

[1]: https://lore.kernel.org/all/20260714113134.3445-1-nikhilgtr@gmail.com/

Vidhu Sarwal (3):
  iio: light: opt4060: Reject integration times with a non-zero seconds
    part
  iio: light: opt4060: Fix pointer type passed to div_u64_rem()
  iio: light: opt4060: Fix incorrect register name in threshold read
    error message

 drivers/iio/light/opt4060.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)


base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
-- 
2.53.0


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

* [PATCH 1/3] iio: light: opt4060: Reject integration times with a non-zero seconds part
  2026-07-15  1:15 [PATCH 0/3] iio: light: opt4060: Fix integration time, pointer type and error message Vidhu Sarwal
@ 2026-07-15  1:15 ` Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 2/3] iio: light: opt4060: Fix pointer type passed to div_u64_rem() Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 3/3] iio: light: opt4060: Fix incorrect register name in threshold read error message Vidhu Sarwal
  2 siblings, 0 replies; 4+ messages in thread
From: Vidhu Sarwal @ 2026-07-15  1:15 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Per-Daniel Olsson,
	linux-iio, linux-kernel, skhan, linux-kernel-mentees,
	Vidhu Sarwal

When setting the integration time, opt4060_write_raw() only uses
val2 and ignores val. As a result, a write such as 1.000600 is
accepted and programmed as 600 us, silently discarding the whole
seconds part.

Since all supported integration times are less than one second, any
non-zero val represents an invalid input. Reject such values instead
of silently accepting them.

Fixes: 0c6db4506ad0 ("iio: light: Add support for TI OPT4060 color sensor")
Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com>
---
 drivers/iio/light/opt4060.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
index c391ad3271c6..cf6f69e5be35 100644
--- a/drivers/iio/light/opt4060.c
+++ b/drivers/iio/light/opt4060.c
@@ -632,6 +632,9 @@ static int opt4060_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_INT_TIME:
+		if (val)
+			return -EINVAL;
+
 		int_time = opt4060_als_time_to_index(val2);
 		if (int_time < 0)
 			return int_time;
-- 
2.53.0


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

* [PATCH 2/3] iio: light: opt4060: Fix pointer type passed to div_u64_rem()
  2026-07-15  1:15 [PATCH 0/3] iio: light: opt4060: Fix integration time, pointer type and error message Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 1/3] iio: light: opt4060: Reject integration times with a non-zero seconds part Vidhu Sarwal
@ 2026-07-15  1:15 ` Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 3/3] iio: light: opt4060: Fix incorrect register name in threshold read error message Vidhu Sarwal
  2 siblings, 0 replies; 4+ messages in thread
From: Vidhu Sarwal @ 2026-07-15  1:15 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Per-Daniel Olsson,
	linux-iio, linux-kernel, skhan, linux-kernel-mentees,
	Vidhu Sarwal

div_u64_rem() expects a u32 * for the remainder, but
opt4060_read_ev_period() passes val2, which is declared as an
int *. While this has no functional impact, it triggers a pointer type
mismatch.

There is no behavioural change because int and u32 have the same
size and representation on all supported architectures, and the
remainder is always less than MICRO, so it fits within the positive
range of int.

Use a local u32 to receive the remainder before assigning it to
*val2.

Fixes: 0c6db4506ad0 ("iio: light: Add support for TI OPT4060 color sensor")
Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com>
---
 drivers/iio/light/opt4060.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
index cf6f69e5be35..e3aabfb14d5d 100644
--- a/drivers/iio/light/opt4060.c
+++ b/drivers/iio/light/opt4060.c
@@ -713,6 +713,7 @@ static ssize_t opt4060_read_ev_period(struct opt4060_chip *chip, int *val,
 {
 	int ret, pers, fault_count, int_time;
 	u64 uval;
+	u32 rem;
 
 	int_time = opt4060_int_time_reg[chip->int_time][0];
 
@@ -738,7 +739,8 @@ static ssize_t opt4060_read_ev_period(struct opt4060_chip *chip, int *val,
 	}
 
 	uval = mul_u32_u32(int_time, pers);
-	*val = div_u64_rem(uval, MICRO, val2);
+	*val = div_u64_rem(uval, MICRO, &rem);
+	*val2 = rem;
 
 	return IIO_VAL_INT_PLUS_MICRO;
 }
-- 
2.53.0


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

* [PATCH 3/3] iio: light: opt4060: Fix incorrect register name in threshold read error message
  2026-07-15  1:15 [PATCH 0/3] iio: light: opt4060: Fix integration time, pointer type and error message Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 1/3] iio: light: opt4060: Reject integration times with a non-zero seconds part Vidhu Sarwal
  2026-07-15  1:15 ` [PATCH 2/3] iio: light: opt4060: Fix pointer type passed to div_u64_rem() Vidhu Sarwal
@ 2026-07-15  1:15 ` Vidhu Sarwal
  2 siblings, 0 replies; 4+ messages in thread
From: Vidhu Sarwal @ 2026-07-15  1:15 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Per-Daniel Olsson,
	linux-iio, linux-kernel, skhan, linux-kernel-mentees,
	Vidhu Sarwal

opt4060_get_thresholds() correctly reads OPT4060_THRESHOLD_HIGH, but
logs "Failed to read THRESHOLD_LOW." if the read fails. This is a
copy-and-paste mistake, as the preceding low-threshold read already uses
the correct error message.

Update the error message to reference OPT4060_THRESHOLD_HIGH.

Fixes: 0c6db4506ad0 ("iio: light: Add support for TI OPT4060 color sensor")
Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com>
---
 drivers/iio/light/opt4060.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c
index e3aabfb14d5d..f79dd342937d 100644
--- a/drivers/iio/light/opt4060.c
+++ b/drivers/iio/light/opt4060.c
@@ -810,7 +810,7 @@ static int opt4060_get_thresholds(struct opt4060_chip *chip, u32 *th_lo, u32 *th
 
 	ret = regmap_read(chip->regmap, OPT4060_THRESHOLD_HIGH, &regval);
 	if (ret) {
-		dev_err(chip->dev, "Failed to read THRESHOLD_LOW.\n");
+		dev_err(chip->dev, "Failed to read THRESHOLD_HIGH.\n");
 		return ret;
 	}
 	*th_hi = opt4060_calc_val_from_th_reg(regval);
-- 
2.53.0


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

end of thread, other threads:[~2026-07-15 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15  1:15 [PATCH 0/3] iio: light: opt4060: Fix integration time, pointer type and error message Vidhu Sarwal
2026-07-15  1:15 ` [PATCH 1/3] iio: light: opt4060: Reject integration times with a non-zero seconds part Vidhu Sarwal
2026-07-15  1:15 ` [PATCH 2/3] iio: light: opt4060: Fix pointer type passed to div_u64_rem() Vidhu Sarwal
2026-07-15  1:15 ` [PATCH 3/3] iio: light: opt4060: Fix incorrect register name in threshold read error message Vidhu Sarwal

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