All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec/fs2dt: Fix sorting of device tree
@ 2014-11-13  0:34 Anton Blanchard
  2014-11-13  1:00 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Blanchard @ 2014-11-13  0:34 UTC (permalink / raw)
  To: horms, haren; +Cc: kexec

Commit b02d735bf252 ('ppc64 kdump device_tree sort') added code to
sort device tree properties, but it had a few issues.

A compare routine needs to return -1 and 1. The special case for
sorting properties with unit addresses only returned 1 and ignored
the opposite case, which screwed up the sorting.

We were missing a few more things:

- Need to check both basenames are the same length
- Need to check both basenames match

I noticed this when looking at the NUMA topology after a kexec, and
it had shifted.

Signed-off-by: Anton Blanchard <anton@samba.org>
---
 kexec/fs2dt.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
index 1e5f074..304f6cb 100644
--- a/kexec/fs2dt.c
+++ b/kexec/fs2dt.c
@@ -479,6 +479,8 @@ static int comparefunc(const struct dirent **dentry1,
 {
 	char *str1 = (*(struct dirent **)dentry1)->d_name;
 	char *str2 = (*(struct dirent **)dentry2)->d_name;
+	char *sep1 = strchr(str1, '@');
+	char *sep2 = strchr(str2, '@');
 
 	/*
 	 * strcmp scans from left to right and fails to idetify for some
@@ -486,9 +488,20 @@ static int comparefunc(const struct dirent **dentry1,
 	 * Therefore, we get the wrong sorted order like memory@10000000 and
 	 * memory@f000000.
 	 */
-	if (strchr(str1, '@') && strchr(str2, '@') &&
-		(strlen(str1) > strlen(str2)))
-		return 1;
+	if (sep1 && sep2) {
+		int baselen1 = sep1 - str1;
+		int baselen2 = sep2 - str2;
+		int len1 = strlen(str1);
+		int len2 = strlen(str2);
+
+		/*
+		 * Check the base name matches, and the properties are
+		 * different lengths.
+		 */
+		if ((baselen1 == baselen2) && (len1 != len2) &&
+		    !strncmp(str1, str2, baselen2))
+			return (len1 > len2) - (len1 < len2);
+	}
 
 	return strcmp(str1, str2);
 }
-- 
1.9.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH] kexec/fs2dt: Fix sorting of device tree
  2014-11-13  0:34 [PATCH] kexec/fs2dt: Fix sorting of device tree Anton Blanchard
@ 2014-11-13  1:00 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2014-11-13  1:00 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: kexec, haren

On Thu, Nov 13, 2014 at 11:34:18AM +1100, Anton Blanchard wrote:
> Commit b02d735bf252 ('ppc64 kdump device_tree sort') added code to
> sort device tree properties, but it had a few issues.
> 
> A compare routine needs to return -1 and 1. The special case for
> sorting properties with unit addresses only returned 1 and ignored
> the opposite case, which screwed up the sorting.
> 
> We were missing a few more things:
> 
> - Need to check both basenames are the same length
> - Need to check both basenames match
> 
> I noticed this when looking at the NUMA topology after a kexec, and
> it had shifted.
> 
> Signed-off-by: Anton Blanchard <anton@samba.org>

Thanks Anton, applied.

> ---
>  kexec/fs2dt.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
> index 1e5f074..304f6cb 100644
> --- a/kexec/fs2dt.c
> +++ b/kexec/fs2dt.c
> @@ -479,6 +479,8 @@ static int comparefunc(const struct dirent **dentry1,
>  {
>  	char *str1 = (*(struct dirent **)dentry1)->d_name;
>  	char *str2 = (*(struct dirent **)dentry2)->d_name;
> +	char *sep1 = strchr(str1, '@');
> +	char *sep2 = strchr(str2, '@');
>  
>  	/*
>  	 * strcmp scans from left to right and fails to idetify for some
> @@ -486,9 +488,20 @@ static int comparefunc(const struct dirent **dentry1,
>  	 * Therefore, we get the wrong sorted order like memory@10000000 and
>  	 * memory@f000000.
>  	 */
> -	if (strchr(str1, '@') && strchr(str2, '@') &&
> -		(strlen(str1) > strlen(str2)))
> -		return 1;
> +	if (sep1 && sep2) {
> +		int baselen1 = sep1 - str1;
> +		int baselen2 = sep2 - str2;
> +		int len1 = strlen(str1);
> +		int len2 = strlen(str2);
> +
> +		/*
> +		 * Check the base name matches, and the properties are
> +		 * different lengths.
> +		 */
> +		if ((baselen1 == baselen2) && (len1 != len2) &&
> +		    !strncmp(str1, str2, baselen2))
> +			return (len1 > len2) - (len1 < len2);
> +	}
>  
>  	return strcmp(str1, str2);
>  }
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2014-11-13  1:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-13  0:34 [PATCH] kexec/fs2dt: Fix sorting of device tree Anton Blanchard
2014-11-13  1:00 ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.