Staging: most: Do not print message if kzalloc() failed.
[linux/fpc-iii.git] / lib / list_debug.c
blob3345a089ef7b954d475d67965b8ce891c1b16ab0
1 /*
2 * Copyright 2006, Red Hat, Inc., Dave Jones
3 * Released under the General Public License (GPL).
5 * This file contains the linked list implementations for
6 * DEBUG_LIST.
7 */
9 #include <linux/export.h>
10 #include <linux/list.h>
11 #include <linux/bug.h>
12 #include <linux/kernel.h>
13 #include <linux/rculist.h>
15 static struct list_head force_poison;
16 void list_force_poison(struct list_head *entry)
18 entry->next = &force_poison;
19 entry->prev = &force_poison;
23 * Insert a new entry between two known consecutive entries.
25 * This is only for internal list manipulation where we know
26 * the prev/next entries already!
29 void __list_add(struct list_head *new,
30 struct list_head *prev,
31 struct list_head *next)
33 WARN(new->next == &force_poison || new->prev == &force_poison,
34 "list_add attempted on force-poisoned entry\n");
35 WARN(next->prev != prev,
36 "list_add corruption. next->prev should be "
37 "prev (%p), but was %p. (next=%p).\n",
38 prev, next->prev, next);
39 WARN(prev->next != next,
40 "list_add corruption. prev->next should be "
41 "next (%p), but was %p. (prev=%p).\n",
42 next, prev->next, prev);
43 WARN(new == prev || new == next,
44 "list_add double add: new=%p, prev=%p, next=%p.\n",
45 new, prev, next);
46 next->prev = new;
47 new->next = next;
48 new->prev = prev;
49 WRITE_ONCE(prev->next, new);
51 EXPORT_SYMBOL(__list_add);
53 void __list_del_entry(struct list_head *entry)
55 struct list_head *prev, *next;
57 prev = entry->prev;
58 next = entry->next;
60 if (WARN(next == LIST_POISON1,
61 "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
62 entry, LIST_POISON1) ||
63 WARN(prev == LIST_POISON2,
64 "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
65 entry, LIST_POISON2) ||
66 WARN(prev->next != entry,
67 "list_del corruption. prev->next should be %p, "
68 "but was %p\n", entry, prev->next) ||
69 WARN(next->prev != entry,
70 "list_del corruption. next->prev should be %p, "
71 "but was %p\n", entry, next->prev))
72 return;
74 __list_del(prev, next);
76 EXPORT_SYMBOL(__list_del_entry);
78 /**
79 * list_del - deletes entry from list.
80 * @entry: the element to delete from the list.
81 * Note: list_empty on entry does not return true after this, the entry is
82 * in an undefined state.
84 void list_del(struct list_head *entry)
86 __list_del_entry(entry);
87 entry->next = LIST_POISON1;
88 entry->prev = LIST_POISON2;
90 EXPORT_SYMBOL(list_del);
93 * RCU variants.
95 void __list_add_rcu(struct list_head *new,
96 struct list_head *prev, struct list_head *next)
98 WARN(next->prev != prev,
99 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
100 prev, next->prev, next);
101 WARN(prev->next != next,
102 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
103 next, prev->next, prev);
104 new->next = next;
105 new->prev = prev;
106 rcu_assign_pointer(list_next_rcu(prev), new);
107 next->prev = new;
109 EXPORT_SYMBOL(__list_add_rcu);