Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: mc13xxx: Fix NULL pointer error in non-DT mode

Add a check to avoid NULL pointer dereference error when
booted in non-DT mode. While at it also remove the additional
of_node_get which is no longer needed for of_get_child_by_name
and fix the node pointer.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Reported-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Sachin Kamat and committed by
Mark Brown
bf7f882b fc5a6e5b

+8 -4
+8 -4
drivers/regulator/mc13xxx-regulator-core.c
··· 167 167 struct device_node *parent; 168 168 int num; 169 169 170 - of_node_get(pdev->dev.parent->of_node); 171 - parent = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); 170 + if (!pdev->dev.of_node) 171 + return -ENODEV; 172 + 173 + parent = of_get_child_by_name(pdev->dev.of_node, "regulators"); 172 174 if (!parent) 173 175 return -ENODEV; 174 176 ··· 189 187 struct device_node *parent, *child; 190 188 int i, parsed = 0; 191 189 192 - of_node_get(pdev->dev.parent->of_node); 193 - parent = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); 190 + if (!pdev->dev.of_node) 191 + return NULL; 192 + 193 + parent = of_get_child_by_name(pdev->dev.of_node, "regulators"); 194 194 if (!parent) 195 195 return NULL; 196 196