xfrm_hash.c 802 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* xfrm_hash.c: Common hash table code.
  3. *
  4. * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/mm.h>
  8. #include <linux/bootmem.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/xfrm.h>
  12. #include "xfrm_hash.h"
  13. struct hlist_head *xfrm_hash_alloc(unsigned int sz)
  14. {
  15. struct hlist_head *n;
  16. if (sz <= PAGE_SIZE)
  17. n = kzalloc(sz, GFP_KERNEL);
  18. else if (hashdist)
  19. n = vzalloc(sz);
  20. else
  21. n = (struct hlist_head *)
  22. __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
  23. get_order(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. }