Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 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 | |
Paul Gortmaker | 8bc3bcc | 2011-11-16 21:29:17 -0500 | [diff] [blame] | 9 | #include <linux/export.h> |
Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 10 | #include <linux/list.h> |
Paul Gortmaker | 50af5ea | 2012-01-20 18:35:53 -0500 | [diff] [blame] | 11 | #include <linux/bug.h> |
Paul Gortmaker | b116ee4 | 2012-01-20 18:46:49 -0500 | [diff] [blame] | 12 | #include <linux/kernel.h> |
Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 13 | |
| 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 | |
| 21 | void __list_add(struct list_head *new, |
| 22 | struct list_head *prev, |
| 23 | struct list_head *next) |
| 24 | { |
Dave Jones | 924d9ad | 2008-07-25 01:45:55 -0700 | [diff] [blame] | 25 | 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 Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 33 | next->prev = new; |
| 34 | new->next = next; |
| 35 | new->prev = prev; |
| 36 | prev->next = new; |
| 37 | } |
| 38 | EXPORT_SYMBOL(__list_add); |
| 39 | |
Linus Torvalds | 3c18d4d | 2011-02-18 11:32:28 -0800 | [diff] [blame] | 40 | void __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 | } |
| 63 | EXPORT_SYMBOL(__list_del_entry); |
| 64 | |
Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 65 | /** |
Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 66 | * 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 | */ |
| 71 | void list_del(struct list_head *entry) |
| 72 | { |
Linus Torvalds | 3c18d4d | 2011-02-18 11:32:28 -0800 | [diff] [blame] | 73 | __list_del_entry(entry); |
Dave Jones | 199a9af | 2006-09-29 01:59:00 -0700 | [diff] [blame] | 74 | entry->next = LIST_POISON1; |
| 75 | entry->prev = LIST_POISON2; |
| 76 | } |
| 77 | EXPORT_SYMBOL(list_del); |