blob: c7a1f0b6a78a389390bd9f0a6217e4fae0163915 [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 Gortmaker8bc3bcc2011-11-16 21:29:17 -050011#include <linux/kernel.h>
Dave Jones199a9af2006-09-29 01:59:00 -070012
13/*
14 * Insert a new entry between two known consecutive entries.
15 *
16 * This is only for internal list manipulation where we know
17 * the prev/next entries already!
18 */
19
20void __list_add(struct list_head *new,
21 struct list_head *prev,
22 struct list_head *next)
23{
Dave Jones924d9ad2008-07-25 01:45:55 -070024 WARN(next->prev != prev,
25 "list_add corruption. next->prev should be "
26 "prev (%p), but was %p. (next=%p).\n",
27 prev, next->prev, next);
28 WARN(prev->next != next,
29 "list_add corruption. prev->next should be "
30 "next (%p), but was %p. (prev=%p).\n",
31 next, prev->next, prev);
Dave Jones199a9af2006-09-29 01:59:00 -070032 next->prev = new;
33 new->next = next;
34 new->prev = prev;
35 prev->next = new;
36}
37EXPORT_SYMBOL(__list_add);
38
Linus Torvalds3c18d4d2011-02-18 11:32:28 -080039void __list_del_entry(struct list_head *entry)
40{
41 struct list_head *prev, *next;
42
43 prev = entry->prev;
44 next = entry->next;
45
46 if (WARN(next == LIST_POISON1,
47 "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
48 entry, LIST_POISON1) ||
49 WARN(prev == LIST_POISON2,
50 "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
51 entry, LIST_POISON2) ||
52 WARN(prev->next != entry,
53 "list_del corruption. prev->next should be %p, "
54 "but was %p\n", entry, prev->next) ||
55 WARN(next->prev != entry,
56 "list_del corruption. next->prev should be %p, "
57 "but was %p\n", entry, next->prev))
58 return;
59
60 __list_del(prev, next);
61}
62EXPORT_SYMBOL(__list_del_entry);
63
Dave Jones199a9af2006-09-29 01:59:00 -070064/**
Dave Jones199a9af2006-09-29 01:59:00 -070065 * list_del - deletes entry from list.
66 * @entry: the element to delete from the list.
67 * Note: list_empty on entry does not return true after this, the entry is
68 * in an undefined state.
69 */
70void list_del(struct list_head *entry)
71{
Linus Torvalds3c18d4d2011-02-18 11:32:28 -080072 __list_del_entry(entry);
Dave Jones199a9af2006-09-29 01:59:00 -070073 entry->next = LIST_POISON1;
74 entry->prev = LIST_POISON2;
75}
76EXPORT_SYMBOL(list_del);