Blame view

net/xfrm/xfrm_hash.c 802 Bytes
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
44e36b42a   David S. Miller   [XFRM]: Extract c...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /* xfrm_hash.c: Common hash table code.
   *
   * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
   */
  
  #include <linux/kernel.h>
  #include <linux/mm.h>
  #include <linux/bootmem.h>
  #include <linux/vmalloc.h>
  #include <linux/slab.h>
  #include <linux/xfrm.h>
  
  #include "xfrm_hash.h"
  
  struct hlist_head *xfrm_hash_alloc(unsigned int sz)
  {
  	struct hlist_head *n;
  
  	if (sz <= PAGE_SIZE)
dcaee95a1   Joonwoo Park   [IPSEC]: kmalloc ...
21
  		n = kzalloc(sz, GFP_KERNEL);
44e36b42a   David S. Miller   [XFRM]: Extract c...
22
  	else if (hashdist)
7a1c8e5ab   Eric Dumazet   net: allow GFP_HI...
23
  		n = vzalloc(sz);
44e36b42a   David S. Miller   [XFRM]: Extract c...
24
25
  	else
  		n = (struct hlist_head *)
dcaee95a1   Joonwoo Park   [IPSEC]: kmalloc ...
26
  			__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
6253db055   Herbert Xu   [IPSEC]: Don't wa...
27
  					 get_order(sz));
44e36b42a   David S. Miller   [XFRM]: Extract c...
28

44e36b42a   David S. Miller   [XFRM]: Extract c...
29
30
31
32
33
34
35
36
37
38
39
40
  	return n;
  }
  
  void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
  {
  	if (sz <= PAGE_SIZE)
  		kfree(n);
  	else if (hashdist)
  		vfree(n);
  	else
  		free_pages((unsigned long)n, get_order(sz));
  }