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: [email protected] Reviewed-by: Peter Griffin <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: André Draszik <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Signed-off-by: Ulf Hansson <[email protected]>
1 parent 211ddde commit 90c8294

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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)