blob: 982b850d4e7aa2aa4b60bd7b08226c07a3c7fca1 [file] [log] [blame]
Dave Jones199a9af2006-09-29 01:59:00 -07001/*
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
Paul Gortmaker8bc3bcc2011-11-16 21:29:17 -05009#include <linux/export.h>
Dave Jones199a9af2006-09-29 01:59:00 -070010#include <linux/list.h>
Paul Gortmaker50af5ea2012-01-20 18:35:53 -050011#include <linux/bug.h>
Paul Gortmakerb116ee42012-01-20 18:46:49 -050012#include <linux/kernel.h>
Dave Jones199a9af2006-09-29 01:59:00 -070013
14/*
15 * Insert a new entry between two known consecutive entries.
16 *
17 * This is only for internal list manipulation where we know
18 * the prev/next entries already!
19 */
20
21void __list_add(struct list_head *new,
22 struct list_head *prev,
23 struct list_head *next)
24{
Dave Jones924d9ad2008-07-25 01:45:55 -070025 WARN(next->prev != prev,
26 "list_add corruption. next->prev should be "
27 "prev (%p), but was %p. (next=%p).\n",
28 prev, next->prev, next);
29 WARN(prev->next != next,
30 "list_add corruption. prev->next should be "
31 "next (%p), but was %p. (prev=%p).\n",
32 next, prev->next, prev);
Dave Jones199a9af2006-09-29 01:59:00 -070033 next->prev = new;
34 new->next = next;
35 new->prev = prev;
36 prev->next = new;
37}
38EXPORT_SYMBOL(__list_add);
39
Linus Torvalds3c18d4d2011-02-18 11:32:28 -080040void __list_del_entry(struct list_head *entry)
41{
42 struct list_head *prev, *next;
43
44 prev = entry->prev;
45 next = entry->next;
46
47 if (WARN(next == LIST_POISON1,
48 "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
49 entry, LIST_POISON1) ||
50 WARN(prev == LIST_POISON2,
51 "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
52 entry, LIST_POISON2) ||
53 WARN(prev->next != entry,
54 "list_del corruption. prev->next should be %p, "
55 "but was %p\n", entry, prev->next) ||
56 WARN(next->prev != entry,
57 "list_del corruption. next->prev should be %p, "
58 "but was %p\n", entry, next->prev))
59 return;
60
61 __list_del(prev, next);
62}
63EXPORT_SYMBOL(__list_del_entry);
64
Dave Jones199a9af2006-09-29 01:59:00 -070065/**
Dave Jones199a9af2006-09-29 01:59:00 -070066 * list_del - deletes entry from list.
67 * @entry: the element to delete from the list.
68 * Note: list_empty on entry does not return true after this, the entry is
69 * in an undefined state.
70 */
71void list_del(struct list_head *entry)
72{
Linus Torvalds3c18d4d2011-02-18 11:32:28 -080073 __list_del_entry(entry);
Dave Jones199a9af2006-09-29 01:59:00 -070074 entry->next = LIST_POISON1;
75 entry->prev = LIST_POISON2;
76}
77EXPORT_SYMBOL(list_del);