Skip to contentSkip to conversation

lib: list_sort_test(): Return -ENOMEM when allocation fails

PATCH Superseded Rasmus Villemoes 1 participant 3 messages Jun 20, 2014 – Jun 23, 2014 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib: list_sort_test(): Return -ENOMEM when allocation fails

---
 lib/list_sort.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/list_sort.c +2 -1
index 1183fa7..291412a 100644
@@ -207,7 +207,7 @@ static int __init cmp(void *priv, struct list_head *a, struct list_head *b)
 
 static int __init list_sort_test(void)
 {
-	int i, count = 1, err = -EINVAL;
+	int i, count = 1, err = -ENOMEM;
 	struct debug_el *el;
 	struct list_head *cur, *tmp;
 	LIST_HEAD(head);
@@ -239,6 +239,7 @@ static int __init list_sort_test(void)
 
 	list_sort(NULL, &head, cmp);
 
+	err = -EINVAL;
 	for (cur = head.next; cur->next != &head; cur = cur->next) {
 		struct debug_el *el1;
 		int cmp_result;
Signature · 1 line
1.9.2
#1 lore raw

PATCH 2/2 lib: list_sort_test(): Add extra corruption check

Add a check to make sure that the prev pointer of the list head points to the last element on the list.

---
 lib/list_sort.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/list_sort.c +5 -0
index 291412a..832f525 100644
@@ -272,6 +272,11 @@ static int __init list_sort_test(void)
 		}
 		count++;
 	}
+	if (head->prev != cur) {
+		printk(KERN_ERR "list_sort_test: error: list is corrupted\n");
+		goto exit;
+	}
+
 
 	if (count != TEST_LIST_LEN) {
 		printk(KERN_ERR "list_sort_test: error: bad list length %d",
Signature · 1 line
1.9.2
#2 lore raw

Re: [PATCH 2/2] lib: list_sort_test(): Add extra corruption check

Quoted 13 lines · Rasmus Villemoes

Add a check to make sure that the prev pointer of the list head points to the last element on the list.

---
 lib/list_sort.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/list_sort.c +0 -0
index 291412a..832f525 100644

lib/list_sort.c static int __init list_sort_test(void) · line 275

Quoted 4 lines
lib/list_sort.c +1 -0
@@ -272,6 +272,11 @@ static int __init list_sort_test(void)
 		}
 		count++;
 	}
+	if (head->prev != cur) {

Scratch that, should be head.prev. Obviously I forgot TEST_LIST_SORT=y when test-compiling. Anyway, I have a few other things I'd like to propose for list_sort.c. Revised patches on their way; sorry for the noise.

Rasmus