Commit 3636e821 authored by Colin Ian King's avatar Colin Ian King Committed by Krzysztof Kozlowski

soc: samsung: chipid: Fix memory leak in error path

Currently when the call to product_id_to_soc_id fails there
is a memory leak of soc_dev_attr->revision and soc_dev_attr
on the error return path.  Fix this by adding a common error
return path that frees there obects and use this for two
error return paths.

Addresses-Coverity: ("Resource leak")
Fixes: 3253b7b7 ("soc: samsung: Add exynos chipid driver support")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
parent 40d8aff6
...@@ -81,15 +81,15 @@ int __init exynos_chipid_early_init(void) ...@@ -81,15 +81,15 @@ int __init exynos_chipid_early_init(void)
soc_dev_attr->soc_id = product_id_to_soc_id(product_id); soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
if (!soc_dev_attr->soc_id) { if (!soc_dev_attr->soc_id) {
pr_err("Unknown SoC\n"); pr_err("Unknown SoC\n");
return -ENODEV; ret = -ENODEV;
goto err;
} }
/* please note that the actual registration will be deferred */ /* please note that the actual registration will be deferred */
soc_dev = soc_device_register(soc_dev_attr); soc_dev = soc_device_register(soc_dev_attr);
if (IS_ERR(soc_dev)) { if (IS_ERR(soc_dev)) {
kfree(soc_dev_attr->revision); ret = PTR_ERR(soc_dev);
kfree(soc_dev_attr); goto err;
return PTR_ERR(soc_dev);
} }
/* it is too early to use dev_info() here (soc_dev is NULL) */ /* it is too early to use dev_info() here (soc_dev is NULL) */
...@@ -97,5 +97,11 @@ int __init exynos_chipid_early_init(void) ...@@ -97,5 +97,11 @@ int __init exynos_chipid_early_init(void)
soc_dev_attr->soc_id, product_id, revision); soc_dev_attr->soc_id, product_id, revision);
return 0; return 0;
err:
kfree(soc_dev_attr->revision);
kfree(soc_dev_attr);
return ret;
} }
early_initcall(exynos_chipid_early_init); early_initcall(exynos_chipid_early_init);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment