Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* xfrm_hash.c: Common hash table code.
0003  *
0004  * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
0005  */
0006 
0007 #include <linux/kernel.h>
0008 #include <linux/mm.h>
0009 #include <linux/memblock.h>
0010 #include <linux/vmalloc.h>
0011 #include <linux/slab.h>
0012 #include <linux/xfrm.h>
0013 
0014 #include "xfrm_hash.h"
0015 
0016 struct hlist_head *xfrm_hash_alloc(unsigned int sz)
0017 {
0018     struct hlist_head *n;
0019 
0020     if (sz <= PAGE_SIZE)
0021         n = kzalloc(sz, GFP_KERNEL);
0022     else if (hashdist)
0023         n = vzalloc(sz);
0024     else
0025         n = (struct hlist_head *)
0026             __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
0027                      get_order(sz));
0028 
0029     return n;
0030 }
0031 
0032 void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
0033 {
0034     if (sz <= PAGE_SIZE)
0035         kfree(n);
0036     else if (hashdist)
0037         vfree(n);
0038     else
0039         free_pages((unsigned long)n, get_order(sz));
0040 }