[RESEND PATCH v2 2/3] ARM: EXYNOS: Handle of_find_device_by_node and kstrdup failures

From: Krzysztof Kozlowski
Date: Wed Apr 22 2015 - 09:18:03 EST


From: Krzysztof Kozlowski <k.kozlowski@xxxxxxxxxxx>

Prevent possible NULL pointer dereference of pointer returned by
of_find_device_by_node(). Handle this by skipping such power domain.

Additionally fail the init on kstrdup() failure. Such case is actually
not fatal because the name for power domain allocated by kstrdup() is
used only in printk. Still as a precaution handle this as an error
condition.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@xxxxxxxxxxx>

---
Changes since v1:
None.
---
arch/arm/mach-exynos/pm_domains.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index 14622b5f4481..61c32ccc9f7a 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -126,6 +126,12 @@ static __init int exynos4_pm_init_power_domain(void)
struct device *dev;

pdev = of_find_device_by_node(np);
+ if (!pdev) {
+ pr_err("%s: failed to find device for node %s\n",
+ __func__, np->name);
+ of_node_put(np);
+ continue;
+ }
dev = &pdev->dev;

pd = kzalloc(sizeof(*pd), GFP_KERNEL);
@@ -136,6 +142,12 @@ static __init int exynos4_pm_init_power_domain(void)
}

pd->pd.name = kstrdup(dev_name(dev), GFP_KERNEL);
+ if (!pd->pd.name) {
+ kfree(pd);
+ of_node_put(np);
+ return -ENOMEM;
+ }
+
pd->name = pd->pd.name;
pd->base = of_iomap(np, 0);
if (!pd->base) {
--
2.1.0

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