list_debug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if (unlikely(next->prev != prev)) {
  21. printk(KERN_ERR "list_add corruption. next->prev should be "
  22. "prev (%p), but was %p. (next=%p).\n",
  23. prev, next->prev, next);
  24. BUG();
  25. }
  26. if (unlikely(prev->next != next)) {
  27. printk(KERN_ERR "list_add corruption. prev->next should be "
  28. "next (%p), but was %p. (prev=%p).\n",
  29. next, prev->next, prev);
  30. BUG();
  31. }
  32. next->prev = new;
  33. new->next = next;
  34. new->prev = prev;
  35. prev->next = new;
  36. }
  37. EXPORT_SYMBOL(__list_add);
  38. /**
  39. * list_add - add a new entry
  40. * @new: new entry to be added
  41. * @head: list head to add it after
  42. *
  43. * Insert a new entry after the specified head.
  44. * This is good for implementing stacks.
  45. */
  46. void list_add(struct list_head *new, struct list_head *head)
  47. {
  48. __list_add(new, head, head->next);
  49. }
  50. EXPORT_SYMBOL(list_add);
  51. /**
  52. * list_del - deletes entry from list.
  53. * @entry: the element to delete from the list.
  54. * Note: list_empty on entry does not return true after this, the entry is
  55. * in an undefined state.
  56. */
  57. void list_del(struct list_head *entry)
  58. {
  59. if (unlikely(entry->prev->next != entry)) {
  60. printk(KERN_ERR "list_del corruption. prev->next should be %p, "
  61. "but was %p\n", entry, entry->prev->next);
  62. BUG();
  63. }
  64. if (unlikely(entry->next->prev != entry)) {
  65. printk(KERN_ERR "list_del corruption. next->prev should be %p, "
  66. "but was %p\n", entry, entry->next->prev);
  67. BUG();
  68. }
  69. __list_del(entry->prev, entry->next);
  70. entry->next = LIST_POISON1;
  71. entry->prev = LIST_POISON2;
  72. }
  73. EXPORT_SYMBOL(list_del);