提交 a46d9884 编写于 作者: A Andy Shevchenko 提交者: Michael Ellerman

powerpc/pseries: handle nodes without '/'

In case we have node without '/' strrchr() returns NULL which might lead to
crash. Replace strrchr() by kbasename() and modify condition to avoid such
behaviour.
Suggested-by: NSegher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
上级 a030e1e4
......@@ -17,14 +17,14 @@ struct device_node *pseries_of_derive_parent(const char *path)
{
struct device_node *parent;
char *parent_path = "/";
size_t parent_path_len = strrchr(path, '/') - path + 1;
const char *tail = kbasename(path);
/* reject if path is "/" */
if (!strcmp(path, "/"))
return ERR_PTR(-EINVAL);
if (strrchr(path, '/') != path) {
parent_path = kstrndup(path, parent_path_len, GFP_KERNEL);
if (tail > path + 1) {
parent_path = kstrndup(path, tail - path, GFP_KERNEL);
if (!parent_path)
return ERR_PTR(-ENOMEM);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册