list_debug.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <linux/export.h>
  9. #include <linux/list.h>
  10. #include <linux/bug.h>
  11. #include <linux/kernel.h>
  12. /*
  13. * Insert a new entry between two known consecutive entries.
  14. *
  15. * This is only for internal list manipulation where we know
  16. * the prev/next entries already!
  17. */
  18. void __list_add(struct list_head *new,
  19. struct list_head *prev,
  20. struct list_head *next)
  21. {
  22. WARN(next->prev != prev,
  23. "list_add corruption. next->prev should be "
  24. "prev (%p), but was %p. (next=%p).\n",
  25. prev, next->prev, next);
  26. WARN(prev->next != next,
  27. "list_add corruption. prev->next should be "
  28. "next (%p), but was %p. (prev=%p).\n",
  29. next, prev->next, prev);
  30. next->prev = new;
  31. new->next = next;
  32. new->prev = prev;
  33. prev->next = new;
  34. }
  35. EXPORT_SYMBOL(__list_add);
  36. void __list_del_entry(struct list_head *entry)
  37. {
  38. struct list_head *prev, *next;
  39. prev = entry->prev;
  40. next = entry->next;
  41. if (WARN(next == LIST_POISON1,
  42. "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  43. entry, LIST_POISON1) ||
  44. WARN(prev == LIST_POISON2,
  45. "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  46. entry, LIST_POISON2) ||
  47. WARN(prev->next != entry,
  48. "list_del corruption. prev->next should be %p, "
  49. "but was %p\n", entry, prev->next) ||
  50. WARN(next->prev != entry,
  51. "list_del corruption. next->prev should be %p, "
  52. "but was %p\n", entry, next->prev))
  53. return;
  54. __list_del(prev, next);
  55. }
  56. EXPORT_SYMBOL(__list_del_entry);
  57. /**
  58. * list_del - deletes entry from list.
  59. * @entry: the element to delete from the list.
  60. * Note: list_empty on entry does not return true after this, the entry is
  61. * in an undefined state.
  62. */
  63. void list_del(struct list_head *entry)
  64. {
  65. __list_del_entry(entry);
  66. entry->next = LIST_POISON1;
  67. entry->prev = LIST_POISON2;
  68. }
  69. EXPORT_SYMBOL(list_del);