list_debug.c 2.3 KB

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