Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries: Correct string length in pseries_of_derive_parent()

Commit a030e1e4bbd085bbcfd0a23f8d355fcd41f39bed make a change to use
kstrndup() instead of kmalloc() + strlcpy() in the pseries_of_derive_parent()
routine that introduces a subtle change in the parent path name generated.
The kstrndup() routine will copy n characters followed by a terminating null,
whereas strlcpy() will copy n-1 characters and add a terminating null.

This slight difference results in having a parent path that includes the
tailing '/' character, "/cpus/" vs. "/cpus". This then causes the subsequent
call to of_find_node_by_path() to fail, and in the case of DLPAR add
operations the DLPAR request fails.

This patch decrements the pointer returned from kbasename() to point to the
'/' character before the base name instead of the base name. This then
adjusts the string length calculations to not include the trailing '/'
in the parent path name.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Nathan Fontenot and committed by
Michael Ellerman
f755ecfb 353169ac

+5 -2
+5 -2
arch/powerpc/platforms/pseries/of_helpers.c
··· 17 17 { 18 18 struct device_node *parent; 19 19 char *parent_path = "/"; 20 - const char *tail = kbasename(path); 20 + const char *tail; 21 + 22 + /* We do not want the trailing '/' character */ 23 + tail = kbasename(path) - 1; 21 24 22 25 /* reject if path is "/" */ 23 26 if (!strcmp(path, "/")) 24 27 return ERR_PTR(-EINVAL); 25 28 26 - if (tail > path + 1) { 29 + if (tail > path) { 27 30 parent_path = kstrndup(path, tail - path, GFP_KERNEL); 28 31 if (!parent_path) 29 32 return ERR_PTR(-ENOMEM);