summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2015-10-01 12:46:07 +0300
committerMichael Ellerman <mpe@ellerman.id.au>2015-10-05 21:11:25 +1100
commitdc85aaed64804205c476d06cebe4c94f66fd8a20 (patch)
treef10c338a4e927857280b22fcc1138ef5aac54cf5
parent948ad1acaf456b7213731cd9eb58654930335070 (diff)
powerpc/pseries: fix a potential memory leak
In case we have a full node name like /foo/bar and /foo is not found the parent_path left unfreed. So, free a memory before return to a caller. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/platforms/pseries/of_helpers.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/arch/powerpc/platforms/pseries/of_helpers.c b/arch/powerpc/platforms/pseries/of_helpers.c
index 1cbd89614484..2f363e3286d1 100644
--- a/arch/powerpc/platforms/pseries/of_helpers.c
+++ b/arch/powerpc/platforms/pseries/of_helpers.c
@@ -15,7 +15,7 @@
*/
struct device_node *pseries_of_derive_parent(const char *path)
{
- struct device_node *parent = NULL;
+ struct device_node *parent;
char *parent_path = "/";
size_t parent_path_len = strrchr(path, '/') - path + 1;
@@ -30,9 +30,7 @@ struct device_node *pseries_of_derive_parent(const char *path)
strlcpy(parent_path, path, parent_path_len);
}
parent = of_find_node_by_path(parent_path);
- if (!parent)
- return ERR_PTR(-EINVAL);
if (strcmp(parent_path, "/"))
kfree(parent_path);
- return parent;
+ return parent ? parent : ERR_PTR(-EINVAL);
}