Skip to contentSkip to conversation

iio: light: al3010: fix incorrect scale for the highest gain range

PATCH Superseded Vidhu Sarwal 3 participants 6 messages Jul 2 – Jul 4 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: light: al3010: fix incorrect scale for the highest gain range

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as {1, 187200}.

Since write_raw() compares the value from userspace against this table, writing 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

Fixes c36b5195ab70 ("iio: light: add Dyna-Image AL3010 driver")
---
 drivers/iio/light/al3010.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/al3010.c +1 -1
index d603b4a6b8e8..cc39f8af4ea3 100644
@@ -42,7 +42,7 @@ enum al3xxxx_range {
 };
 
 static const int al3010_scales[][2] = {
-	{0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600}
+	{1, 187200}, {0, 296800}, {0, 74200}, {0, 18600}
 };
 
 static const struct regmap_config al3010_regmap_config = {
Signature · 1 line
2.53.0
#1 lore raw
Quoted 10 lines · Vidhu Sarwal

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as {1, 187200}.

Since write_raw() compares the value from userspace against this table, writing 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

Trailing spaces in the last line of the above paragraph.

Quoted 3 lines
Fixes c36b5195ab70 ("iio: light: add Dyna-Image AL3010 driver")

...

drivers/iio/light/al3010.c enum al3xxxx_range { · line 45

Quoted 3 lines

static const int al3010_scales[][2] = {

drivers/iio/light/al3010.c +1 -1
-	{0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600}
+	{1, 187200}, {0, 296800}, {0, 74200}, {0, 18600}

While at it, add a trailing comma.

Quoted 1 line

};

Otherwise LGTM, thanks.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
Quoted 18 lines · On Thu, 2 Jul 2026 12:44:54 +0300 Andy Shevchenko…
Quoted 10 lines · Vidhu Sarwal

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as {1, 187200}.

Since write_raw() compares the value from userspace against this table, writing 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

Trailing spaces in the last line of the above paragraph.

Quoted 3 lines
Fixes c36b5195ab70 ("iio: light: add Dyna-Image AL3010 driver")
Quoted 7 lines

...

drivers/iio/light/al3010.c enum al3xxxx_range { · line 45

Quoted 3 lines

static const int al3010_scales[][2] = {

drivers/iio/light/al3010.c +1 -1
-	{0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600}
+	{1, 187200}, {0, 296800}, {0, 74200}, {0, 18600}  

While at it, add a trailing comma.

Can we take opportunity to move to IIO (well my) preferred formatting

	{ 1, 187200 }, { 0, 296800 }, { 0, 74200 }, { 0, 18600 },  

Thanks,

Jonathan

Quoted 5 lines
Quoted 2 lines

};

Otherwise LGTM, thanks.

#3 lore raw

PATCH v2 1/1 iio: light: al3010: fix incorrect scale for the highest gain range

In reply to Vidhu Sarwal

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as { 1, 187200 }.

Since write_raw() compares the value from userspace against this table, writing the advertised 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

Fixes c36b5195ab70 ("iio: light: add Dyna-Image AL3010 driver")

---
v2:
- Remove trailing whitespace in commit message and Add trailing comma after last array element (Andy)
- Use IIO preferred brace spacing (Jonathan)

 drivers/iio/light/al3010.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/al3010.c +1 -1
index d603b4a6b8e8..ca1d7fd6defb 100644
@@ -42,7 +42,7 @@ enum al3xxxx_range {
 };
 
 static const int al3010_scales[][2] = {
-	{0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600}
+	{ 1, 187200 }, { 0, 296800 }, { 0, 74200 }, { 0, 18600 },
 };
 
 static const struct regmap_config al3010_regmap_config = {
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#4 lore raw
Quoted 10 lines · Vidhu Sarwal

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as { 1, 187200 }.

Since write_raw() compares the value from userspace against this table, writing the advertised 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
Quoted 6 lines · On Sat, 4 Jul 2026 15:13:42 +0300 Andy Shevchenko…
Quoted 5 lines · Vidhu Sarwal

al3010_scales[] encodes the highest gain range as {0, 1187200}. For IIO_VAL_INT_PLUS_MICRO, the fractional part must be less than 1000000, so the scale 1.1872 should instead be represented as { 1, 187200 }.

Quoted 8 lines
Quoted 5 lines

Since write_raw() compares the value from userspace against this table, writing the advertised 1.1872 scale never matches the malformed entry and returns -EINVAL. As a result, the highest gain range cannot be selected. Reading the scale in that state also reports the malformed value.

For future reference, please never send a new version in reply to an earlier version. It both gets very confusing as threads develop and also puts your patches way back in the maintainers inbox, which often slows down getting them applied.

Applied and marked for stable

thanks, Jonathan