iio: light: opt4060: Fix integration time, pointer type and error message
cover iio: light: opt4060: Fix integration time, pointer type and error message
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/[email protected]/
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
Signature · 1 line
2.53.0
PATCH 1/3 iio: light: opt4060: Reject integration times with a non-zero seconds part
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.
--- drivers/iio/light/opt4060.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/light/opt4060.c +3 -0
@@ -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;
Signature · 1 line
2.53.0
PATCH 2/3 iio: light: opt4060: Fix pointer type passed to div_u64_rem()
In reply to Vidhu Sarwaldiv_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.
--- drivers/iio/light/opt4060.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/light/opt4060.c +3 -1
@@ -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 ; }
Signature · 1 line
2.53.0
PATCH 3/3 iio: light: opt4060: Fix incorrect register name in threshold read error message
In reply to Vidhu Sarwalopt4060_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.
--- drivers/iio/light/opt4060.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/opt4060.c +1 -1
@@ -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 , ®val);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);
Signature · 1 line
2.53.0
Quoted 12 lines · On Wed, 15 Jul 2026 06:45:41 +0530 Vidhu Sarwal <[email protected]> wrote:
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.
Quoted 7 lines
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.
All 3 applied to the fixes-togreg branch of iio.git.
I marked patches 1 and 3 for stable. The second one as you note isn't a bug with affects as such so is less important to backport.
Nice little series.
Thanks,
Jonathan
Quoted 15 lines
[1]: https://lore.kernel.org/all/[email protected]/
Vidhu Sarwal (3):
iio: light: opt4060: Reject integration times with a non-zero seconds
part
iio: light: opt4060: Fix pointer type passed todiv_u64_rem()
iio: light: opt4060: Fix incorrect register name in threshold read
error messagedrivers/iio/light/opt4060.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)base-commit:
a13c140cc289c0b7b3770bce5b3ad42ab35074aa