Skip to content

Commit da26296

Browse files
GustavoARSilvabroonie
authored andcommitted
regulator: axp20x: add NULL check on devm_kzalloc() return value
Check return value from call to devm_kzalloc() in order to prevent a NULL pointer dereference. This issue was detected using Coccinelle and the following semantic patch: @@ expression x; identifier fld; @@ * x = devm_kzalloc(...); ... when != x == NULL x->fld Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 8d67f64 commit da26296

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/regulator/axp20x-regulator.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
691691
(regulators == axp809_regulators && i == AXP809_DC1SW)) {
692692
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
693693
GFP_KERNEL);
694+
if (!new_desc)
695+
return -ENOMEM;
696+
694697
*new_desc = regulators[i];
695698
new_desc->supply_name = dcdc1_name;
696699
desc = new_desc;
@@ -700,6 +703,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
700703
(regulators == axp809_regulators && i == AXP809_DC5LDO)) {
701704
new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
702705
GFP_KERNEL);
706+
if (!new_desc)
707+
return -ENOMEM;
708+
703709
*new_desc = regulators[i];
704710
new_desc->supply_name = dcdc5_name;
705711
desc = new_desc;

0 commit comments

Comments
 (0)