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 <[email protected]>
Reported-by: Philippe Rétornaz <[email protected]>
---
 drivers/regulator/mc13xxx-regulator-core.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/mc13xxx-regulator-core.c 
b/drivers/regulator/mc13xxx-regulator-core.c
index 4498a3f0733d..bf75fcabfa3c 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -167,8 +167,10 @@ int mc13xxx_get_num_regulators_dt(struct platform_device 
*pdev)
        struct device_node *parent;
        int num;
 
-       of_node_get(pdev->dev.parent->of_node);
-       parent = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
+       if (!pdev->dev.of_node)
+               return -ENODEV;
+
+       parent = of_get_child_by_name(pdev->dev.of_node, "regulators");
        if (!parent)
                return -ENODEV;
 
@@ -187,8 +189,10 @@ struct mc13xxx_regulator_init_data 
*mc13xxx_parse_regulators_dt(
        struct device_node *parent, *child;
        int i, parsed = 0;
 
-       of_node_get(pdev->dev.parent->of_node);
-       parent = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
+       if (!pdev->dev.of_node)
+               return NULL;
+
+       parent = of_get_child_by_name(pdev->dev.of_node, "regulators");
        if (!parent)
                return NULL;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to