list_debug.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /**
  35. * list_del - deletes entry from list.
  36. * @entry: the element to delete from the list.
  37. * Note: list_empty on entry does not return true after this, the entry is
  38. * in an undefined state.
  39. */
  40. void list_del(struct list_head *entry)
  41. {
  42. WARN(entry->prev->next != entry,
  43. "list_del corruption. prev->next should be %p, "
  44. "but was %p\n", entry, entry->prev->next);
  45. WARN(entry->next->prev != entry,
  46. "list_del corruption. next->prev should be %p, "
  47. "but was %p\n", entry, entry->next->prev);
  48. __list_del(entry->prev, entry->next);
  49. entry->next = LIST_POISON1;
  50. entry->prev = LIST_POISON2;
  51. }
  52. EXPORT_SYMBOL(list_del);