From: Phil Carmody <ext-phil.2.carmody@nokia.com>
To: menage@google.com, lizf@cn.fujitsu.com
Cc: containers@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
ext-phil.2.carmody@nokia.com
Subject: [PATCH 1/2] list.h: add debug version of list_empty
Date: Tue, 15 Mar 2011 15:08:42 +0200 [thread overview]
Message-ID: <1300194523-19325-2-git-send-email-ext-phil.2.carmody@nokia.com> (raw)
In-Reply-To: <1300194523-19325-1-git-send-email-ext-phil.2.carmody@nokia.com>
Heed the notice in list_del: "Note: list_empty() on entry does not
return true after this, the entry is in an undefined state.", and
check for precisely that condition.
There are currently a few instances in the code of this sequence:
if(!list_empty(pnode))
list_del(pnode);
which seems to be useless or dangerous if intended to protect from
repeated del's. And given that I've seen an oops pointing to a
dereference of poison in such a list_empty, I'm veering towards
dangerous. This patch would make such errors obvious.
Nothing is changed in the non-DEBUG_LIST build.
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
---
include/linux/list.h | 4 ++++
lib/list_debug.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/include/linux/list.h b/include/linux/list.h
index 3a54266..59bebd1 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -183,10 +183,14 @@ static inline int list_is_last(const struct list_head *list,
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
+#ifndef CONFIG_DEBUG_LIST
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
+#else
+extern int list_empty(const struct list_head *head);
+#endif
/**
* list_empty_careful - tests whether a list is empty and not being modified
diff --git a/lib/list_debug.c b/lib/list_debug.c
index b8029a5..aaba728 100644
--- a/lib/list_debug.c
+++ b/lib/list_debug.c
@@ -73,3 +73,21 @@ void list_del(struct list_head *entry)
entry->prev = LIST_POISON2;
}
EXPORT_SYMBOL(list_del);
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+int list_empty(const struct list_head *head)
+{
+ if ((head->prev == LIST_POISON2) || (head->prev == LIST_POISON1))
+ WARN(1, "list_empty performed on a node "
+ "at %p removed from a list.\n", head);
+ else
+ WARN((head->prev == head) != (head->next == head),
+ "list_empty corruption. %p<-%p->%p is half-empty.\n",
+ head->prev, head, head->next);
+
+ return head->next == head;
+}
+EXPORT_SYMBOL(list_empty);
--
1.7.2.rc1.37.gf8c40
next prev parent reply other threads:[~2011-03-15 13:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 13:08 [PATCH 0/2] suck some poison out of cgroups' linked lists Phil Carmody
2011-03-15 13:08 ` Phil Carmody [this message]
2011-03-15 13:08 ` [PATCH 2/2] cgroup: if you list_empty() a head then don't list_del() it Phil Carmody
2011-03-15 16:20 ` Paul Menage
2011-03-15 16:35 ` Kirill A. Shutemov
2011-03-21 23:52 ` [PATCH 1/2] list.h: add debug version of list_empty Andrew Morton
2011-03-22 10:11 ` Phil Carmody
2011-03-22 10:18 ` Kirill A. Shutemov
2011-03-15 13:51 ` [PATCH 0/2] suck some poison out of cgroups' linked lists Christoph Hellwig
2011-03-15 14:01 ` Phil Carmody
2011-03-15 14:12 ` ext Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300194523-19325-2-git-send-email-ext-phil.2.carmody@nokia.com \
--to=ext-phil.2.carmody@nokia.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®