list_debug.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if (unlikely(entry->prev->next != entry)) {
  58. printk(KERN_ERR "list_del corruption. prev->next should be %p, but was %p\n",
  59. entry, entry->prev->next);
  60. BUG();
  61. }
  62. if (unlikely(entry->next->prev != entry)) {
  63. printk(KERN_ERR "list_del corruption. next->prev should be %p, but was %p\n",
  64. entry, entry->next->prev);
  65. BUG();
  66. }
  67. __list_del(entry->prev, entry->next);
  68. entry->next = LIST_POISON1;
  69. entry->prev = LIST_POISON2;
  70. }
  71. EXPORT_SYMBOL(list_del);