Re: [PATCH] iio: ina2xx-adc: fix regmap max_register off-by-one

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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 <[email protected]>
> ---
> Found by static analysis using smatch, code review and guess work.
> NOT TESTED.  Please review carefully!

Right, see above.

-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.