xfrm_hash.c 809 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 = kmalloc(sz, GFP_KERNEL);
  17. else if (hashdist)
  18. n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL);
  19. else
  20. n = (struct hlist_head *)
  21. __get_free_pages(GFP_KERNEL | __GFP_NOWARN,
  22. get_order(sz));
  23. if (n)
  24. memset(n, 0, sz);
  25. return n;
  26. }
  27. void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
  28. {
  29. if (sz <= PAGE_SIZE)
  30. kfree(n);
  31. else if (hashdist)
  32. vfree(n);
  33. else
  34. free_pages((unsigned long)n, get_order(sz));
  35. }