xfrm_hash.c 766 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* xfrm_hash.c: Common hash table code.
  2. *
  3. * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/mm.h>
  7. #include <linux/bootmem.h>
  8. #include <linux/vmalloc.h>
  9. #include <linux/slab.h>
  10. #include <linux/xfrm.h>
  11. #include "xfrm_hash.h"
  12. struct hlist_head *xfrm_hash_alloc(unsigned int sz)
  13. {
  14. struct hlist_head *n;
  15. if (sz <= PAGE_SIZE)
  16. n = kzalloc(sz, GFP_KERNEL);
  17. else if (hashdist)
  18. n = vzalloc(sz);
  19. else
  20. n = (struct hlist_head *)
  21. __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
  22. get_order(sz));
  23. return n;
  24. }
  25. void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
  26. {
  27. if (sz <= PAGE_SIZE)
  28. kfree(n);
  29. else if (hashdist)
  30. vfree(n);
  31. else
  32. free_pages((unsigned long)n, get_order(sz));
  33. }