Skip to content

Commit 920ac5b

Browse files
krzksre
authored andcommitted
power: max8925: Fix NULL ptr dereference on memory allocation failure
Check the return value of devm_kzalloc() to fix possible NULL pointer dereference and properly exit the probe() on memory allocation failure. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
1 parent 628ef02 commit 920ac5b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎drivers/power/max8925_power.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,23 @@ max8925_power_dt_init(struct platform_device *pdev)
452452
pdata = devm_kzalloc(&pdev->dev,
453453
sizeof(struct max8925_power_pdata),
454454
GFP_KERNEL);
455+
if (!pdata)
456+
goto ret;
455457

456458
of_property_read_u32(np, "topoff-threshold", &topoff_threshold);
457459
of_property_read_u32(np, "batt-detect", &batt_detect);
458460
of_property_read_u32(np, "fast-charge", &fast_charge);
459461
of_property_read_u32(np, "no-insert-detect", &no_insert_detect);
460462
of_property_read_u32(np, "no-temp-support", &no_temp_support);
461-
of_node_put(np);
462463

463464
pdata->batt_detect = batt_detect;
464465
pdata->fast_charge = fast_charge;
465466
pdata->topoff_threshold = topoff_threshold;
466467
pdata->no_insert_detect = no_insert_detect;
467468
pdata->no_temp_support = no_temp_support;
468469

470+
ret:
471+
of_node_put(np);
469472
return pdata;
470473
}
471474
#else

0 commit comments

Comments
 (0)