summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/kexec/kexec-tools/kexec-tools-Refine-kdump-device_tree-sort.patch
blob: ab1fe96db2b627c381e0538a590630f5a50b369f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
kexec-tools: Refine kdump device_tree sort

The commit b02d735bf was to rearrange the device-tree entries, and
assumed that these entries are sorted in the ascending order. but
acctually when I was validating kexec and kdump, the order of
serial node still is changed. So the patch is to sort these entries
by the directory name in ascending order.

Upstream-Status: Pending

Signed-off-by: Yang Wei <Wei.Yang@windriver.com>
Signed-off-by: Chong Lu <Chong.Lu@windriver.com>
---
 kexec/arch/ppc/fs2dt.c |   13 ++++++++++---
 kexec/fs2dt.c          |   13 ++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
index 4121c7d..cc04b04 100644
--- a/kexec/arch/ppc/fs2dt.c
+++ b/kexec/arch/ppc/fs2dt.c
@@ -296,6 +296,9 @@ static int comparefunc(const void *dentry1, const void *dentry2)
 {
 	char *str1 = (*(struct dirent **)dentry1)->d_name;
 	char *str2 = (*(struct dirent **)dentry2)->d_name;
+	char* ptr1 = strchr(str1, '@');
+	char* ptr2 = strchr(str2, '@');
+	int len1, len2;
 
 	/*
 	 * strcmp scans from left to right and fails to idetify for some
@@ -303,9 +306,13 @@ static int comparefunc(const void *dentry1, const void *dentry2)
 	 * 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 (ptr1 && ptr2) {
+		len1 = ptr1 - str1;
+		len2 = ptr2 - str2;
+		if (!strncmp(str1, str2, len1 >len2 ? len1: len2) &&
+					(strlen(str1) > strlen(str2)))
+				return 1;
+	}
 
 	return strcmp(str1, str2);
 }
diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
index 5e6b98d..1c0345b 100644
--- a/kexec/fs2dt.c
+++ b/kexec/fs2dt.c
@@ -475,6 +475,9 @@ static int comparefunc(const struct dirent **dentry1,
 {
 	char *str1 = (*(struct dirent **)dentry1)->d_name;
 	char *str2 = (*(struct dirent **)dentry2)->d_name;
+	char* ptr1 = strchr(str1, '@');
+	char* ptr2 = strchr(str2, '@');
+	int len1, len2;
 
 	/*
 	 * strcmp scans from left to right and fails to idetify for some
@@ -482,9 +485,13 @@ 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 (ptr1 && ptr2) {
+		len1 = ptr1 - str1;
+		len2 = ptr2 - str2;
+		if (!strncmp(str1, str2, len1 >len2 ? len1: len2) &&
+					(strlen(str1) > strlen(str2)))
+				return 1;
+	}
 
 	return strcmp(str1, str2);
 }
-- 
1.7.9.5

OpenPOWER on IntegriCloud