list_debug.c 2.6 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/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. next->prev = new;
  35. new->next = next;
  36. new->prev = prev;
  37. WRITE_ONCE(prev->next, new);
  38. }
  39. EXPORT_SYMBOL(__list_add);
  40. void __list_del_entry(struct list_head *entry)
  41. {
  42. struct list_head *prev, *next;
  43. prev = entry->prev;
  44. next = entry->next;
  45. if (WARN(next == LIST_POISON1,
  46. "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  47. entry, LIST_POISON1) ||
  48. WARN(prev == LIST_POISON2,
  49. "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  50. entry, LIST_POISON2) ||
  51. WARN(prev->next != entry,
  52. "list_del corruption. prev->next should be %p, "
  53. "but was %p\n", entry, prev->next) ||
  54. WARN(next->prev != entry,
  55. "list_del corruption. next->prev should be %p, "
  56. "but was %p\n", entry, next->prev))
  57. return;
  58. __list_del(prev, next);
  59. }
  60. EXPORT_SYMBOL(__list_del_entry);
  61. /**
  62. * list_del - deletes entry from list.
  63. * @entry: the element to delete from the list.
  64. * Note: list_empty on entry does not return true after this, the entry is
  65. * in an undefined state.
  66. */
  67. void list_del(struct list_head *entry)
  68. {
  69. __list_del_entry(entry);
  70. entry->next = LIST_POISON1;
  71. entry->prev = LIST_POISON2;
  72. }
  73. EXPORT_SYMBOL(list_del);
  74. /*
  75. * RCU variants.
  76. */
  77. void __list_add_rcu(struct list_head *new,
  78. struct list_head *prev, struct list_head *next)
  79. {
  80. WARN(next->prev != prev,
  81. "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
  82. prev, next->prev, next);
  83. WARN(prev->next != next,
  84. "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
  85. next, prev->next, prev);
  86. new->next = next;
  87. new->prev = prev;
  88. rcu_assign_pointer(list_next_rcu(prev), new);
  89. next->prev = new;
  90. }
  91. EXPORT_SYMBOL(__list_add_rcu);