diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2015-10-01 12:46:09 +0300 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-10-05 21:11:27 +1100 |
commit | a46d9884096c15ec17505b9b3d19f5e0672deff3 (patch) | |
tree | 830a62cc1791d48c974fc47d9c60345316dcf2c1 /arch/powerpc/platforms/pseries/of_helpers.c | |
parent | a030e1e4bbd085bbcfd0a23f8d355fcd41f39bed (diff) | |
download | linux-a46d9884096c15ec17505b9b3d19f5e0672deff3.tar.bz2 |
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: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch/powerpc/platforms/pseries/of_helpers.c')
-rw-r--r-- | arch/powerpc/platforms/pseries/of_helpers.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/arch/powerpc/platforms/pseries/of_helpers.c b/arch/powerpc/platforms/pseries/of_helpers.c index 8c6b05ae1a1d..4417afef74d4 100644 --- a/arch/powerpc/platforms/pseries/of_helpers.c +++ b/arch/powerpc/platforms/pseries/of_helpers.c @@ -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); } |