Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da262968 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Mark Brown
Browse files

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: default avatarGustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8d67f64f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -691,6 +691,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
		    (regulators == axp809_regulators && i == AXP809_DC1SW)) {
			new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
						GFP_KERNEL);
			if (!new_desc)
				return -ENOMEM;

			*new_desc = regulators[i];
			new_desc->supply_name = dcdc1_name;
			desc = new_desc;
@@ -700,6 +703,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
		    (regulators == axp809_regulators && i == AXP809_DC5LDO)) {
			new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
						GFP_KERNEL);
			if (!new_desc)
				return -ENOMEM;

			*new_desc = regulators[i];
			new_desc->supply_name = dcdc5_name;
			desc = new_desc;