linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/pseries: Correct string length in pseries_of_derive_parent()
@ 2015-10-27 15:46 Nathan Fontenot
  2015-10-27 15:52 ` Andy Shevchenko
  2015-11-02  9:41 ` [v2] " Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Fontenot @ 2015-10-27 15:46 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Andy Shevchenko

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>
---

Updates for v2: Decrement the pointer returned from kbasename() instead
of subtracting 1 when calculating the string length.
 
 arch/powerpc/platforms/pseries/of_helpers.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/of_helpers.c b/arch/powerpc/platforms/pseries/of_helpers.c
index 4417afe..2798933 100644
--- a/arch/powerpc/platforms/pseries/of_helpers.c
+++ b/arch/powerpc/platforms/pseries/of_helpers.c
@@ -17,13 +17,16 @@ struct device_node *pseries_of_derive_parent(const char *path)
 {
 	struct device_node *parent;
 	char *parent_path = "/";
-	const char *tail = kbasename(path);
+	const char *tail;
+
+	/* We do not want the trailing '/' character */
+	tail = kbasename(path) - 1;
 
 	/* reject if path is "/" */
 	if (!strcmp(path, "/"))
 		return ERR_PTR(-EINVAL);
 
-	if (tail > path + 1) {
+	if (tail > path) {
 		parent_path = kstrndup(path, tail - path, GFP_KERNEL);
 		if (!parent_path)
 			return ERR_PTR(-ENOMEM);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] powerpc/pseries: Correct string length in pseries_of_derive_parent()
  2015-10-27 15:46 [PATCH v2] powerpc/pseries: Correct string length in pseries_of_derive_parent() Nathan Fontenot
@ 2015-10-27 15:52 ` Andy Shevchenko
  2015-11-02  9:41 ` [v2] " Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2015-10-27 15:52 UTC (permalink / raw)
  To: Nathan Fontenot, linuxppc-dev

On Tue, 2015-10-27 at 10:46 -0500, Nathan Fontenot wrote:
> 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>

> ---
> 
> Updates for v2: Decrement the pointer returned from kbasename()
> instead
> of subtracting 1 when calculating the string length.
>  
>  arch/powerpc/platforms/pseries/of_helpers.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/of_helpers.c
> b/arch/powerpc/platforms/pseries/of_helpers.c
> index 4417afe..2798933 100644
> --- a/arch/powerpc/platforms/pseries/of_helpers.c
> +++ b/arch/powerpc/platforms/pseries/of_helpers.c
> @@ -17,13 +17,16 @@ struct device_node
> *pseries_of_derive_parent(const char *path)
>  {
>  	struct device_node *parent;
>  	char *parent_path = "/";
> -	const char *tail = kbasename(path);
> +	const char *tail;
> +
> +	/* We do not want the trailing '/' character */
> +	tail = kbasename(path) - 1;
>  
>  	/* reject if path is "/" */
>  	if (!strcmp(path, "/"))
>  		return ERR_PTR(-EINVAL);
>  
> -	if (tail > path + 1) {
> +	if (tail > path) {
>  		parent_path = kstrndup(path, tail - path,
> GFP_KERNEL);
>  		if (!parent_path)
>  			return ERR_PTR(-ENOMEM);
> 

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [v2] powerpc/pseries: Correct string length in pseries_of_derive_parent()
  2015-10-27 15:46 [PATCH v2] powerpc/pseries: Correct string length in pseries_of_derive_parent() Nathan Fontenot
  2015-10-27 15:52 ` Andy Shevchenko
@ 2015-11-02  9:41 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2015-11-02  9:41 UTC (permalink / raw)
  To: Nathan Fontenot, linuxppc-dev; +Cc: Andy Shevchenko

On Tue, 2015-27-10 at 15:46:47 UTC, Nathan Fontenot wrote:
> 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>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f755ecfb8cec7b19dff84295

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-02  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27 15:46 [PATCH v2] powerpc/pseries: Correct string length in pseries_of_derive_parent() Nathan Fontenot
2015-10-27 15:52 ` Andy Shevchenko
2015-11-02  9:41 ` [v2] " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).