xfrm_hash.c 788 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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, get_order(sz));
  22. if (n)
  23. memset(n, 0, sz);
  24. return n;
  25. }
  26. void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
  27. {
  28. if (sz <= PAGE_SIZE)
  29. kfree(n);
  30. else if (hashdist)
  31. vfree(n);
  32. else
  33. free_pages((unsigned long)n, get_order(sz));
  34. }