From 1ea2927c1bc3c66d2ff69f131268e6be4d38a87c Mon Sep 17 00:00:00 2001 From: Qinguang Xu Date: Tue, 20 Oct 2026 21:39:06 +0800 Subject: [PATCH] regmap: irq: fix incorrect index calculation for read_sub_irq_data() While working on a PMIC driver that utilizes num_main_regs > 1, this issue was noticed. Currently, no in-tree driver sets `num_main_regs > 1`, so this bug has not been triggered in practice. Pass the global index calculated with `i` instead of the local bit offset `b` to read_sub_irq_data(). Fix an off-by-one error in the index bounds check. This patch has been compile-tested only. Signed-off-by: Qinguang Xu Link: https://patch.msgid.link/20261020-debug-v1-1-44e0491ede30@gmail.com Signed-off-by: Mark Brown --- drivers/base/regmap/regmap-irq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 715eb9e7aa2a..8e6d508c4fbd 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c @@ -398,14 +398,14 @@ static int read_irq_data(struct regmap_irq_chip_data *data) /* Read sub registers with active IRQs */ for (i = 0; i < chip->num_main_regs; i++) { - unsigned int b; + unsigned int b, index; const unsigned long mreg = data->main_status_buf[i]; for_each_set_bit(b, &mreg, map->format.val_bytes * 8) { - if (i * map->format.val_bytes * 8 + b > - max_main_bits) + index = i * map->format.val_bytes * 8 + b; + if (index >= max_main_bits) break; - ret = read_sub_irq_data(data, b); + ret = read_sub_irq_data(data, index); if (ret != 0) { dev_err(map->dev, "Failed to read IRQ status %d\n", ret);