Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc85aaed authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Michael Ellerman
Browse files

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 948ad1ac
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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);
}