list_debug.c 2.5 KB

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