* [PATCH 1/2] list: unify hlist_add functions
@ 2009-03-15 15:23 Akinobu Mita
2009-03-15 15:25 ` [PATCH 2/2] list: DEBUG_LIST for hlist Akinobu Mita
0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2009-03-15 15:23 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm
Unify hlist_add_head(), hlist_add_before(), and hlist_add_after().
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
include/linux/list.h | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
Index: 2.6/include/linux/list.h
===================================================================
--- 2.6.orig/include/linux/list.h
+++ 2.6/include/linux/list.h
@@ -588,35 +588,36 @@ static inline void hlist_del_init(struct
}
}
+/*
+ * This is only for internal hlist manipulation where we know
+ * the pprev/next entries already!
+ */
+static inline void __hlist_add(struct hlist_node *new,
+ struct hlist_node **pprev, struct hlist_node *next)
+{
+ new->next = next;
+ if (next)
+ next->pprev = &new->next;
+ *pprev = new;
+ new->pprev = pprev;
+}
+
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
- struct hlist_node *first = h->first;
- n->next = first;
- if (first)
- first->pprev = &n->next;
- h->first = n;
- n->pprev = &h->first;
+ __hlist_add(n, &h->first, h->first);
}
/* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *next)
{
- n->pprev = next->pprev;
- n->next = next;
- next->pprev = &n->next;
- *(n->pprev) = n;
+ __hlist_add(n, next->pprev, next);
}
static inline void hlist_add_after(struct hlist_node *n,
struct hlist_node *next)
{
- next->next = n->next;
- n->next = next;
- next->pprev = &n->next;
-
- if(next->next)
- next->next->pprev = &next->next;
+ __hlist_add(next, &n->next, n->next);
}
/*
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] list: DEBUG_LIST for hlist
2009-03-15 15:23 [PATCH 1/2] list: unify hlist_add functions Akinobu Mita
@ 2009-03-15 15:25 ` Akinobu Mita
0 siblings, 0 replies; 2+ messages in thread
From: Akinobu Mita @ 2009-03-15 15:25 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm
Add sanity checks in hlist manipulation when CONFIG_DEBUG_LIST is enabled.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
include/linux/list.h | 18 ++++++++++++++++++
lib/list_debug.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
Index: 2.6/include/linux/list.h
===================================================================
--- 2.6.orig/include/linux/list.h
+++ 2.6/include/linux/list.h
@@ -564,6 +564,12 @@ static inline int hlist_empty(const stru
return !h->first;
}
+#ifdef CONFIG_DEBUG_LIST
+
+extern void __hlist_del(struct hlist_node *n);
+
+#else
+
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *next = n->next;
@@ -573,6 +579,8 @@ static inline void __hlist_del(struct hl
next->pprev = pprev;
}
+#endif
+
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
@@ -592,6 +600,14 @@ static inline void hlist_del_init(struct
* This is only for internal hlist manipulation where we know
* the pprev/next entries already!
*/
+
+#ifdef CONFIG_DEBUG_LIST
+
+extern void __hlist_add(struct hlist_node *new,
+ struct hlist_node **pprev, struct hlist_node *next);
+
+#else
+
static inline void __hlist_add(struct hlist_node *new,
struct hlist_node **pprev, struct hlist_node *next)
{
@@ -602,6 +618,8 @@ static inline void __hlist_add(struct hl
new->pprev = pprev;
}
+#endif
+
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
__hlist_add(n, &h->first, h->first);
Index: 2.6/lib/list_debug.c
===================================================================
--- 2.6.orig/lib/list_debug.c
+++ 2.6/lib/list_debug.c
@@ -54,3 +54,41 @@ void list_del(struct list_head *entry)
entry->prev = LIST_POISON2;
}
EXPORT_SYMBOL(list_del);
+
+void __hlist_del(struct hlist_node *n)
+{
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+
+ WARN(next && next->pprev != &n->next,
+ "hlist_del corruption. next->pprev should be %p, but was %p\n",
+ &n->next, next->pprev);
+ WARN(*pprev != n,
+ "hlist_del corruption. *pprev should be %p, but was %p\n",
+ n, *pprev);
+
+ *pprev = next;
+ if (next)
+ next->pprev = pprev;
+}
+EXPORT_SYMBOL(__hlist_del);
+
+void __hlist_add(struct hlist_node *new,
+ struct hlist_node **pprev, struct hlist_node *next)
+{
+ WARN(next && next->pprev != pprev,
+ "hlist_add corruption. next->pprev should be pprev (%p), "
+ "but was %p. (next=%p).\n",
+ pprev, next->pprev, next);
+ WARN(*pprev != next,
+ "hlist_add corruption. *pprev should be next (%p), "
+ "but was %p. (pprev=%p).\n",
+ next, *pprev, pprev);
+
+ new->next = next;
+ if (next)
+ next->pprev = &new->next;
+ *pprev = new;
+ new->pprev = pprev;
+}
+EXPORT_SYMBOL(__hlist_add);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-15 15:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-15 15:23 [PATCH 1/2] list: unify hlist_add functions Akinobu Mita
2009-03-15 15:25 ` [PATCH 2/2] list: DEBUG_LIST for hlist Akinobu Mita
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox