list_debug.c 2.0 KB

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