1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 244e36b42SDavid S. Miller /* xfrm_hash.c: Common hash table code. 344e36b42SDavid S. Miller * 444e36b42SDavid S. Miller * Copyright (C) 2006 David S. Miller (davem@davemloft.net) 544e36b42SDavid S. Miller */ 644e36b42SDavid S. Miller 744e36b42SDavid S. Miller #include <linux/kernel.h> 844e36b42SDavid S. Miller #include <linux/mm.h> 9*57c8a661SMike Rapoport #include <linux/memblock.h> 1044e36b42SDavid S. Miller #include <linux/vmalloc.h> 1144e36b42SDavid S. Miller #include <linux/slab.h> 1244e36b42SDavid S. Miller #include <linux/xfrm.h> 1344e36b42SDavid S. Miller 1444e36b42SDavid S. Miller #include "xfrm_hash.h" 1544e36b42SDavid S. Miller xfrm_hash_alloc(unsigned int sz)1644e36b42SDavid S. Millerstruct hlist_head *xfrm_hash_alloc(unsigned int sz) 1744e36b42SDavid S. Miller { 1844e36b42SDavid S. Miller struct hlist_head *n; 1944e36b42SDavid S. Miller 2044e36b42SDavid S. Miller if (sz <= PAGE_SIZE) 21dcaee95aSJoonwoo Park n = kzalloc(sz, GFP_KERNEL); 2244e36b42SDavid S. Miller else if (hashdist) 237a1c8e5aSEric Dumazet n = vzalloc(sz); 2444e36b42SDavid S. Miller else 2544e36b42SDavid S. Miller n = (struct hlist_head *) 26dcaee95aSJoonwoo Park __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 276253db05SHerbert Xu get_order(sz)); 2844e36b42SDavid S. Miller 2944e36b42SDavid S. Miller return n; 3044e36b42SDavid S. Miller } 3144e36b42SDavid S. Miller xfrm_hash_free(struct hlist_head * n,unsigned int sz)3244e36b42SDavid S. Millervoid xfrm_hash_free(struct hlist_head *n, unsigned int sz) 3344e36b42SDavid S. Miller { 3444e36b42SDavid S. Miller if (sz <= PAGE_SIZE) 3544e36b42SDavid S. Miller kfree(n); 3644e36b42SDavid S. Miller else if (hashdist) 3744e36b42SDavid S. Miller vfree(n); 3844e36b42SDavid S. Miller else 3944e36b42SDavid S. Miller free_pages((unsigned long)n, get_order(sz)); 4044e36b42SDavid S. Miller } 41