list_debug.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/rculist.h>
  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. void __list_add(struct list_head *new,
  20. struct list_head *prev,
  21. struct list_head *next)
  22. {
  23. WARN(next->prev != prev,
  24. "list_add corruption. next->prev should be "
  25. "prev (%p), but was %p. (next=%p).\n",
  26. prev, next->prev, next);
  27. WARN(prev->next != next,
  28. "list_add corruption. prev->next should be "
  29. "next (%p), but was %p. (prev=%p).\n",
  30. next, prev->next, prev);
  31. WARN(new == prev || new == next,
  32. "list_add double add: new=%p, prev=%p, next=%p.\n",
  33. new, prev, next);
  34. if (next->prev != prev || prev->next != next || new == prev || new == next)
  35. BUG();
  36. next->prev = new;
  37. new->next = next;
  38. new->prev = prev;
  39. prev->next = new;
  40. }
  41. EXPORT_SYMBOL(__list_add);
  42. void __list_del_entry(struct list_head *entry)
  43. {
  44. struct list_head *prev, *next;
  45. prev = entry->prev;
  46. next = entry->next;
  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. BUG();
  60. return;
  61. }
  62. __list_del(prev, next);
  63. }
  64. EXPORT_SYMBOL(__list_del_entry);
  65. /**
  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. {
  73. __list_del_entry(entry);
  74. entry->next = LIST_POISON1;
  75. entry->prev = LIST_POISON2;
  76. }
  77. EXPORT_SYMBOL(list_del);
  78. /*
  79. * RCU variants.
  80. */
  81. void __list_add_rcu(struct list_head *new,
  82. struct list_head *prev, struct list_head *next)
  83. {
  84. WARN(next->prev != prev,
  85. "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
  86. prev, next->prev, next);
  87. WARN(prev->next != next,
  88. "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
  89. next, prev->next, prev);
  90. if (next->prev != prev || prev->next != next)
  91. BUG();
  92. new->next = next;
  93. new->prev = prev;
  94. rcu_assign_pointer(list_next_rcu(prev), new);
  95. next->prev = new;
  96. }
  97. EXPORT_SYMBOL(__list_add_rcu);