list_debug.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/module.h>
  9. #include <linux/list.h>
  10. /*
  11. * Insert a new entry between two known consecutive entries.
  12. *
  13. * This is only for internal list manipulation where we know
  14. * the prev/next entries already!
  15. */
  16. void __list_add(struct list_head *new,
  17. struct list_head *prev,
  18. struct list_head *next)
  19. {
  20. WARN(next->prev != prev,
  21. "list_add corruption. next->prev should be "
  22. "prev (%p), but was %p. (next=%p).\n",
  23. prev, next->prev, next);
  24. WARN(prev->next != next,
  25. "list_add corruption. prev->next should be "
  26. "next (%p), but was %p. (prev=%p).\n",
  27. next, prev->next, prev);
  28. next->prev = new;
  29. new->next = next;
  30. new->prev = prev;
  31. prev->next = new;
  32. }
  33. EXPORT_SYMBOL(__list_add);
  34. void __list_del_entry(struct list_head *entry)
  35. {
  36. struct list_head *prev, *next;
  37. prev = entry->prev;
  38. next = entry->next;
  39. if (WARN(next == LIST_POISON1,
  40. "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  41. entry, LIST_POISON1) ||
  42. WARN(prev == LIST_POISON2,
  43. "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  44. entry, LIST_POISON2) ||
  45. WARN(prev->next != entry,
  46. "list_del corruption. prev->next should be %p, "
  47. "but was %p\n", entry, prev->next) ||
  48. WARN(next->prev != entry,
  49. "list_del corruption. next->prev should be %p, "
  50. "but was %p\n", entry, next->prev))
  51. return;
  52. __list_del(prev, next);
  53. }
  54. EXPORT_SYMBOL(__list_del_entry);
  55. /**
  56. * list_del - deletes entry from list.
  57. * @entry: the element to delete from the list.
  58. * Note: list_empty on entry does not return true after this, the entry is
  59. * in an undefined state.
  60. */
  61. void list_del(struct list_head *entry)
  62. {
  63. __list_del_entry(entry);
  64. entry->next = LIST_POISON1;
  65. entry->prev = LIST_POISON2;
  66. }
  67. EXPORT_SYMBOL(list_del);