blob: 06796dec01ea563346aaf551d8684f07d07d069e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +10002#include <linux/types.h>
3#include <linux/init.h>
4#include <linux/slab.h>
5#include <linux/bootmem.h>
Stephen Rothwell5669c3c2007-10-02 13:37:53 +10006#include <linux/string.h>
David Howellsae3a1972012-03-28 18:30:02 +01007#include <asm/setup.h>
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +10008
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +10009
Fabian Frederickbd721ea2016-08-02 14:03:33 -070010void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
Stephen Rothwell5669c3c2007-10-02 13:37:53 +100011{
12 void *p;
13
Michael Ellermanf691fa12015-03-30 14:10:37 +110014 if (slab_is_available())
Stephen Rothwell5669c3c2007-10-02 13:37:53 +100015 p = kzalloc(size, mask);
16 else {
Michael Ellermane39f223f2014-11-18 16:47:35 +110017 p = memblock_virt_alloc(size, 0);
Stephen Rothwell5669c3c2007-10-02 13:37:53 +100018 }
19 return p;
20}