Skip to content

Commit eeca209

Browse files
shramamoorthybroonie
authored andcommitted
regulator: tps65219: Fix devm_kmalloc size allocation
In probe(), two arrays of structs are allocated with the devm_kmalloc() function, but the memory size of the allocations were given as the arrays' length (pmic->common_irq_size for the first call and pmic->dev_irq_size for the second devm_kmalloc call). The memory size should have been the total memory needed. This led to a heap overflow when the struct array was used. The issue was first discovered with the PocketBeagle2 and BeaglePlay. The common and device-specific structs are now allocated one at a time within the loop. Fixes: 38c9f98 ("regulator: tps65219: Add support for TPS65215 Regulator IRQs") Reported-by: Dhruva Gole <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Robert Nelson <[email protected]> Acked-by: Andrew Davis <[email protected]> Signed-off-by: Shree Ramamoorthy <[email protected]> Reviewed-by: Nishanth Menon <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ca46946 commit eeca209

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drivers/regulator/tps65219-regulator.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -436,46 +436,46 @@ static int tps65219_regulator_probe(struct platform_device *pdev)
436436
pmic->rdesc[i].name);
437437
}
438438

439-
irq_data = devm_kmalloc(tps->dev, pmic->common_irq_size, GFP_KERNEL);
440-
if (!irq_data)
441-
return -ENOMEM;
442-
443439
for (i = 0; i < pmic->common_irq_size; ++i) {
444440
irq_type = &pmic->common_irq_types[i];
445441
irq = platform_get_irq_byname(pdev, irq_type->irq_name);
446442
if (irq < 0)
447443
return -EINVAL;
448444

449-
irq_data[i].dev = tps->dev;
450-
irq_data[i].type = irq_type;
445+
irq_data = devm_kmalloc(tps->dev, sizeof(*irq_data), GFP_KERNEL);
446+
if (!irq_data)
447+
return -ENOMEM;
448+
449+
irq_data->dev = tps->dev;
450+
irq_data->type = irq_type;
451451
error = devm_request_threaded_irq(tps->dev, irq, NULL,
452452
tps65219_regulator_irq_handler,
453453
IRQF_ONESHOT,
454454
irq_type->irq_name,
455-
&irq_data[i]);
455+
irq_data);
456456
if (error)
457457
return dev_err_probe(tps->dev, PTR_ERR(rdev),
458458
"Failed to request %s IRQ %d: %d\n",
459459
irq_type->irq_name, irq, error);
460460
}
461461

462-
irq_data = devm_kmalloc(tps->dev, pmic->dev_irq_size, GFP_KERNEL);
463-
if (!irq_data)
464-
return -ENOMEM;
465-
466462
for (i = 0; i < pmic->dev_irq_size; ++i) {
467463
irq_type = &pmic->irq_types[i];
468464
irq = platform_get_irq_byname(pdev, irq_type->irq_name);
469465
if (irq < 0)
470466
return -EINVAL;
471467

472-
irq_data[i].dev = tps->dev;
473-
irq_data[i].type = irq_type;
468+
irq_data = devm_kmalloc(tps->dev, sizeof(*irq_data), GFP_KERNEL);
469+
if (!irq_data)
470+
return -ENOMEM;
471+
472+
irq_data->dev = tps->dev;
473+
irq_data->type = irq_type;
474474
error = devm_request_threaded_irq(tps->dev, irq, NULL,
475475
tps65219_regulator_irq_handler,
476476
IRQF_ONESHOT,
477477
irq_type->irq_name,
478-
&irq_data[i]);
478+
irq_data);
479479
if (error)
480480
return dev_err_probe(tps->dev, PTR_ERR(rdev),
481481
"Failed to request %s IRQ %d: %d\n",

0 commit comments

Comments
 (0)