linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] lib: list_sort_test(): Return -ENOMEM when allocation fails
@ 2014-06-20 23:49 Rasmus Villemoes
  2014-06-20 23:49 ` [PATCH 2/2] lib: list_sort_test(): Add extra corruption check Rasmus Villemoes
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus Villemoes @ 2014-06-20 23:49 UTC (permalink / raw)
  To: Artem Bityutskiy, Don Mullis, Dave Chinner; +Cc: linux-kernel, Rasmus Villemoes

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 lib/list_sort.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/list_sort.c b/lib/list_sort.c
index 1183fa7..291412a 100644
--- a/lib/list_sort.c
+++ b/lib/list_sort.c
@@ -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;
-- 
1.9.2


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

* [PATCH 2/2] lib: list_sort_test(): Add extra corruption check
  2014-06-20 23:49 [PATCH 1/2] lib: list_sort_test(): Return -ENOMEM when allocation fails Rasmus Villemoes
@ 2014-06-20 23:49 ` Rasmus Villemoes
  2014-06-23 19:15   ` Rasmus Villemoes
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus Villemoes @ 2014-06-20 23:49 UTC (permalink / raw)
  To: Artem Bityutskiy, Don Mullis, Dave Chinner; +Cc: linux-kernel, Rasmus Villemoes

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

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 lib/list_sort.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/list_sort.c b/lib/list_sort.c
index 291412a..832f525 100644
--- a/lib/list_sort.c
+++ b/lib/list_sort.c
@@ -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",
-- 
1.9.2


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

* Re: [PATCH 2/2] lib: list_sort_test(): Add extra corruption check
  2014-06-20 23:49 ` [PATCH 2/2] lib: list_sort_test(): Add extra corruption check Rasmus Villemoes
@ 2014-06-23 19:15   ` Rasmus Villemoes
  0 siblings, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2014-06-23 19:15 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Don Mullis, Dave Chinner, linux-kernel

Rasmus Villemoes <linux@rasmusvillemoes.dk> writes:

> Add a check to make sure that the prev pointer of the list head points
> to the last element on the list.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  lib/list_sort.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/lib/list_sort.c b/lib/list_sort.c
> index 291412a..832f525 100644
> --- a/lib/list_sort.c
> +++ b/lib/list_sort.c
> @@ -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


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

end of thread, other threads:[~2014-06-23 19:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-20 23:49 [PATCH 1/2] lib: list_sort_test(): Return -ENOMEM when allocation fails Rasmus Villemoes
2014-06-20 23:49 ` [PATCH 2/2] lib: list_sort_test(): Add extra corruption check Rasmus Villemoes
2014-06-23 19:15   ` Rasmus Villemoes

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