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

Harshit Mogalapalli <[email protected]>
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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 <[email protected]>
---
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
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.