list_debug.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include <linux/bug.h>
  13. #include <linux/rculist.h>
  14. #if 0
  15. #ifdef CONFIG_SEC_DEBUG_LIST_PANIC
  16. static int list_debug = 0x00000100UL;
  17. #else
  18. static int list_debug;
  19. #endif
  20. #endif
  21. /*
  22. * Insert a new entry between two known consecutive entries.
  23. *
  24. * This is only for internal list manipulation where we know
  25. * the prev/next entries already!
  26. */
  27. void __list_add(struct list_head *new,
  28. struct list_head *prev,
  29. struct list_head *next)
  30. {
  31. WARN(next->prev != prev,
  32. "list_add corruption. next->prev should be "
  33. "prev (%p), but was %p. (next=%p).\n",
  34. prev, next->prev, next);
  35. WARN(prev->next != next,
  36. "list_add corruption. prev->next should be "
  37. "next (%p), but was %p. (prev=%p).\n",
  38. next, prev->next, prev);
  39. #if 0
  40. BUG_ON(((prev->next != next) || (next->prev != prev)) &&
  41. PANIC_CORRUPTION);
  42. #endif
  43. if ((prev->next != next) || (next->prev != prev))
  44. {
  45. panic("list corruption during add");
  46. }
  47. next->prev = new;
  48. new->next = next;
  49. new->prev = prev;
  50. prev->next = new;
  51. }
  52. EXPORT_SYMBOL(__list_add);
  53. void __list_del_entry(struct list_head *entry)
  54. {
  55. struct list_head *prev, *next;
  56. prev = entry->prev;
  57. next = entry->next;
  58. if (WARN(next == LIST_POISON1,
  59. "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  60. entry, LIST_POISON1) ||
  61. WARN(prev == LIST_POISON2,
  62. "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  63. entry, LIST_POISON2) ||
  64. WARN(prev->next != entry,
  65. "list_del corruption. prev->next should be %p, "
  66. "but was %p\n", entry, prev->next) ||
  67. WARN(next->prev != entry,
  68. "list_del corruption. next->prev should be %p, "
  69. "but was %p\n", entry, next->prev)) {
  70. #if 0
  71. BUG_ON(PANIC_CORRUPTION);
  72. #endif
  73. panic("list corruption during del");
  74. return;
  75. }
  76. __list_del(prev, next);
  77. }
  78. EXPORT_SYMBOL(__list_del_entry);
  79. /**
  80. * list_del - deletes entry from list.
  81. * @entry: the element to delete from the list.
  82. * Note: list_empty on entry does not return true after this, the entry is
  83. * in an undefined state.
  84. */
  85. void list_del(struct list_head *entry)
  86. {
  87. __list_del_entry(entry);
  88. entry->next = LIST_POISON1;
  89. entry->prev = LIST_POISON2;
  90. }
  91. EXPORT_SYMBOL(list_del);
  92. /*
  93. * RCU variants.
  94. */
  95. void __list_add_rcu(struct list_head *new,
  96. struct list_head *prev, struct list_head *next)
  97. {
  98. WARN(next->prev != prev,
  99. "list_add_rcu corruption. next->prev should be "
  100. "prev (%p), but was %p. (next=%p).\n",
  101. prev, next->prev, next);
  102. WARN(prev->next != next,
  103. "list_add_rcu corruption. prev->next should be "
  104. "next (%p), but was %p. (prev=%p).\n",
  105. next, prev->next, prev);
  106. new->next = next;
  107. new->prev = prev;
  108. rcu_assign_pointer(list_next_rcu(prev), new);
  109. next->prev = new;
  110. }
  111. EXPORT_SYMBOL(__list_add_rcu);