Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: ina2xx-adc: fix regmap max_register off-by-one
@ 2026-03-25  5:43 Harshit Mogalapalli
  2026-03-25 12:36 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Harshit Mogalapalli @ 2026-03-25  5:43 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Harshit Mogalapalli, Marc Titinger, linux-iio, linux-kernel
  Cc: dan.carpenter, kernel-janitors

regmap_config.max_register is supposed to store the highest valid
register but this driver assigns the number of registers
INA2XX_MAX_REGISTERS is 8, the highest valid register address is 7.

Fix this by subtracting 1 so max_register is inclusive.

Fixes: c43a102e67db ("iio: ina2xx: add support for TI INA2xx Power Monitors")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
Found by static analysis using smatch, code review and guess work.
NOT TESTED.  Please review carefully!
---
 drivers/iio/adc/ina2xx-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 857e1b69d6cd..d200b8e87839 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -116,7 +116,7 @@ static inline bool is_signed_reg(unsigned int reg)
 static const struct regmap_config ina2xx_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 16,
-	.max_register = INA2XX_MAX_REGISTERS,
+	.max_register = INA2XX_MAX_REGISTERS - 1,
 	.writeable_reg = ina2xx_is_writeable_reg,
 	.volatile_reg = ina2xx_is_volatile_reg,
 };
-- 
2.50.1


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

* Re: [PATCH] iio: ina2xx-adc: fix regmap max_register off-by-one
  2026-03-25  5:43 [PATCH] iio: ina2xx-adc: fix regmap max_register off-by-one Harshit Mogalapalli
@ 2026-03-25 12:36 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-03-25 12:36 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Marc Titinger, linux-iio, linux-kernel, dan.carpenter,
	kernel-janitors

On Tue, Mar 24, 2026 at 10:43:09PM -0700, Harshit Mogalapalli wrote:
> regmap_config.max_register is supposed to store the highest valid
> register but this driver assigns the number of registers
> INA2XX_MAX_REGISTERS is 8, the highest valid register address is 7.
> 
> Fix this by subtracting 1 so max_register is inclusive.

This matches with my understanding of max_register in regmap.
But what I have noticed is that we have two drivers for the same subset
of the chips. Why? Also one may note the differences in max_register.

Taking that into account with the fact that most likely there is nothing wrong
to access that register (in the other driver they allow up to 13), I think you
can rather add a 0x07 register to the ADC driver and change the value of
_MAX_REGISTERS to be equal to 0x07 as done in hwmon driver.

> Fixes: c43a102e67db ("iio: ina2xx: add support for TI INA2xx Power Monitors")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> Found by static analysis using smatch, code review and guess work.
> NOT TESTED.  Please review carefully!

Right, see above.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-03-25 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  5:43 [PATCH] iio: ina2xx-adc: fix regmap max_register off-by-one Harshit Mogalapalli
2026-03-25 12:36 ` Andy Shevchenko

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