nvme: fix Kconfig description for BLK_DEV_NVME_SCSI
[linux-2.6-block.git] / lib / list_debug.c
CommitLineData
199a9afc
DJ
1/*
2 * Copyright 2006, Red Hat, Inc., Dave Jones
3 * Released under the General Public License (GPL).
4 *
5 * This file contains the linked list implementations for
6 * DEBUG_LIST.
7 */
8
8bc3bcc9 9#include <linux/export.h>
199a9afc 10#include <linux/list.h>
50af5ead 11#include <linux/bug.h>
b116ee4d 12#include <linux/kernel.h>
559f9bad 13#include <linux/rculist.h>
199a9afc 14
5c2c2587
DW
15static struct list_head force_poison;
16void list_force_poison(struct list_head *entry)
17{
18 entry->next = &force_poison;
19 entry->prev = &force_poison;
20}
21
199a9afc
DJ
22/*
23 * Insert a new entry between two known consecutive entries.
24 *
25 * This is only for internal list manipulation where we know
26 * the prev/next entries already!
27 */
28
29void __list_add(struct list_head *new,
30 struct list_head *prev,
31 struct list_head *next)
32{
5c2c2587
DW
33 WARN(new->next == &force_poison || new->prev == &force_poison,
34 "list_add attempted on force-poisoned entry\n");
924d9add
DJ
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);
17a801f4
CM
43 WARN(new == prev || new == next,
44 "list_add double add: new=%p, prev=%p, next=%p.\n",
45 new, prev, next);
199a9afc
DJ
46 next->prev = new;
47 new->next = next;
48 new->prev = prev;
1c97be67 49 WRITE_ONCE(prev->next, new);
199a9afc
DJ
50}
51EXPORT_SYMBOL(__list_add);
52
3c18d4de
LT
53void __list_del_entry(struct list_head *entry)
54{
55 struct list_head *prev, *next;
56
57 prev = entry->prev;
58 next = entry->next;
59
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;
73
74 __list_del(prev, next);
75}
76EXPORT_SYMBOL(__list_del_entry);
77
199a9afc
DJ
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.
83 */
84void list_del(struct list_head *entry)
85{
3c18d4de 86 __list_del_entry(entry);
199a9afc
DJ
87 entry->next = LIST_POISON1;
88 entry->prev = LIST_POISON2;
89}
90EXPORT_SYMBOL(list_del);
559f9bad
DJ
91
92/*
93 * RCU variants.
94 */
95void __list_add_rcu(struct list_head *new,
96 struct list_head *prev, struct list_head *next)
97{
98 WARN(next->prev != prev,
5cf05ad7 99 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
559f9bad
DJ
100 prev, next->prev, next);
101 WARN(prev->next != next,
5cf05ad7 102 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
559f9bad
DJ
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;
108}
109EXPORT_SYMBOL(__list_add_rcu);