Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | kexec-tools: Refine kdump device_tree sort |
| 2 | |
| 3 | The commit b02d735bf was to rearrange the device-tree entries, and |
| 4 | assumed that these entries are sorted in the ascending order. but |
| 5 | acctually when I was validating kexec and kdump, the order of |
| 6 | serial node still is changed. So the patch is to sort these entries |
| 7 | by the directory name in ascending order. |
| 8 | |
| 9 | Upstream-Status: Pending |
| 10 | |
| 11 | Signed-off-by: Yang Wei <Wei.Yang@windriver.com> |
| 12 | Signed-off-by: Chong Lu <Chong.Lu@windriver.com> |
| 13 | --- |
| 14 | kexec/arch/ppc/fs2dt.c | 13 ++++++++++--- |
| 15 | kexec/fs2dt.c | 13 ++++++++++--- |
| 16 | 2 files changed, 20 insertions(+), 6 deletions(-) |
| 17 | |
| 18 | Index: kexec-tools-2.0.10/kexec/arch/ppc/fs2dt.c |
| 19 | =================================================================== |
| 20 | --- kexec-tools-2.0.10.orig/kexec/arch/ppc/fs2dt.c |
| 21 | +++ kexec-tools-2.0.10/kexec/arch/ppc/fs2dt.c |
| 22 | @@ -296,6 +296,9 @@ static int comparefunc(const void *dentr |
| 23 | { |
| 24 | char *str1 = (*(struct dirent **)dentry1)->d_name; |
| 25 | char *str2 = (*(struct dirent **)dentry2)->d_name; |
| 26 | + char* ptr1 = strchr(str1, '@'); |
| 27 | + char* ptr2 = strchr(str2, '@'); |
| 28 | + int len1, len2; |
| 29 | |
| 30 | /* |
| 31 | * strcmp scans from left to right and fails to idetify for some |
| 32 | @@ -303,9 +306,13 @@ static int comparefunc(const void *dentr |
| 33 | * Therefore, we get the wrong sorted order like memory@10000000 and |
| 34 | * memory@f000000. |
| 35 | */ |
| 36 | - if (strchr(str1, '@') && strchr(str2, '@') && |
| 37 | - (strlen(str1) > strlen(str2))) |
| 38 | - return 1; |
| 39 | + if (ptr1 && ptr2) { |
| 40 | + len1 = ptr1 - str1; |
| 41 | + len2 = ptr2 - str2; |
| 42 | + if (!strncmp(str1, str2, len1 >len2 ? len1: len2) && |
| 43 | + (strlen(str1) > strlen(str2))) |
| 44 | + return 1; |
| 45 | + } |
| 46 | |
| 47 | return strcmp(str1, str2); |
| 48 | } |