Skip to content

Commit 90c8294

Browse files
andredstorulf
authored andcommitted
pmdomain: samsung: plug potential memleak during probe
of_genpd_add_provider_simple() could fail, in which case this code leaks the domain name, pd->pd.name. Use devm_kstrdup_const() to plug this leak. As a side-effect, we can simplify existing error handling. Fixes: c09a3e6 ("soc: samsung: pm_domains: Convert to regular platform driver") Cc: stable@vger.kernel.org Reviewed-by: Peter Griffin <peter.griffin@linaro.org> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Signed-off-by: André Draszik <andre.draszik@linaro.org> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 211ddde commit 90c8294

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

drivers/pmdomain/samsung/exynos-pm-domains.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ static const struct of_device_id exynos_pm_domain_of_match[] = {
9292
{ },
9393
};
9494

95-
static const char *exynos_get_domain_name(struct device_node *node)
95+
static const char *exynos_get_domain_name(struct device *dev,
96+
struct device_node *node)
9697
{
9798
const char *name;
9899

99100
if (of_property_read_string(node, "label", &name) < 0)
100101
name = kbasename(node->full_name);
101-
return kstrdup_const(name, GFP_KERNEL);
102+
return devm_kstrdup_const(dev, name, GFP_KERNEL);
102103
}
103104

104105
static int exynos_pd_probe(struct platform_device *pdev)
@@ -115,15 +116,13 @@ static int exynos_pd_probe(struct platform_device *pdev)
115116
if (!pd)
116117
return -ENOMEM;
117118

118-
pd->pd.name = exynos_get_domain_name(np);
119+
pd->pd.name = exynos_get_domain_name(dev, np);
119120
if (!pd->pd.name)
120121
return -ENOMEM;
121122

122123
pd->base = of_iomap(np, 0);
123-
if (!pd->base) {
124-
kfree_const(pd->pd.name);
124+
if (!pd->base)
125125
return -ENODEV;
126-
}
127126

128127
pd->pd.power_off = exynos_pd_power_off;
129128
pd->pd.power_on = exynos_pd_power_on;

0 commit comments

Comments
 (0)