Skip to content

Commit ca0e36e

Browse files
jneannebroonie
authored andcommitted
regulator: tps6594-regulator: Fix random kernel crash
Random kernel crash detected in TI CICD when regulator driver is added. This is root caused to irq index increment being done twice causing irq_data being allocated outside of the range. - Rework tps6594_request_reg_irqs with correct index increment - Adjust irq_data kmalloc size to the exact size needed for the device This has been reported on TI mainline. No public bug report associated. Reported-by: Udit Kumar <u-kumar1@ti.com> Fixes: f17ccc5 ("regulator: tps6594-regulator: Add driver for TI TPS6594 regulators") Signed-off-by: Jerome Neanne <jneanne@baylibre.com> Link: https://lore.kernel.org/r/20230828-tps6594_random_boot_crash_fix-v1-1-f29cbf9ddb37@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c692905 commit ca0e36e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

drivers/regulator/tps6594-regulator.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,19 @@ static int tps6594_request_reg_irqs(struct platform_device *pdev,
384384
if (irq < 0)
385385
return -EINVAL;
386386

387-
irq_data[*irq_idx + j].dev = tps->dev;
388-
irq_data[*irq_idx + j].type = irq_type;
389-
irq_data[*irq_idx + j].rdev = rdev;
387+
irq_data[*irq_idx].dev = tps->dev;
388+
irq_data[*irq_idx].type = irq_type;
389+
irq_data[*irq_idx].rdev = rdev;
390390

391391
error = devm_request_threaded_irq(tps->dev, irq, NULL,
392-
tps6594_regulator_irq_handler,
393-
IRQF_ONESHOT,
394-
irq_type->irq_name,
395-
&irq_data[*irq_idx]);
396-
(*irq_idx)++;
392+
tps6594_regulator_irq_handler, IRQF_ONESHOT,
393+
irq_type->irq_name, &irq_data[*irq_idx]);
397394
if (error) {
398395
dev_err(tps->dev, "tps6594 failed to request %s IRQ %d: %d\n",
399396
irq_type->irq_name, irq, error);
400397
return error;
401398
}
399+
(*irq_idx)++;
402400
}
403401
return 0;
404402
}
@@ -420,8 +418,8 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
420418
int error, i, irq, multi, delta;
421419
int irq_idx = 0;
422420
int buck_idx = 0;
423-
int ext_reg_irq_nb = 2;
424-
421+
size_t ext_reg_irq_nb = 2;
422+
size_t reg_irq_nb;
425423
enum {
426424
MULTI_BUCK12,
427425
MULTI_BUCK123,
@@ -484,15 +482,16 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
484482
}
485483
}
486484

487-
if (tps->chip_id == LP8764)
485+
if (tps->chip_id == LP8764) {
488486
/* There is only 4 buck on LP8764 */
489487
buck_configured[4] = 1;
488+
reg_irq_nb = size_mul(REGS_INT_NB, (BUCK_NB - 1));
489+
} else {
490+
reg_irq_nb = size_mul(REGS_INT_NB, (size_add(BUCK_NB, LDO_NB)));
491+
}
490492

491-
irq_data = devm_kmalloc_array(tps->dev,
492-
REGS_INT_NB * sizeof(struct tps6594_regulator_irq_data),
493-
ARRAY_SIZE(tps6594_bucks_irq_types) +
494-
ARRAY_SIZE(tps6594_ldos_irq_types),
495-
GFP_KERNEL);
493+
irq_data = devm_kmalloc_array(tps->dev, reg_irq_nb,
494+
sizeof(struct tps6594_regulator_irq_data), GFP_KERNEL);
496495
if (!irq_data)
497496
return -ENOMEM;
498497

0 commit comments

Comments
 (0)