blob: 5b61704447c18bfb54920413ed27e2b60a0f9505 [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>
Mike Rapoport57c8a662018-10-30 15:09:49 -07005#include <linux/memblock.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 {
Mike Rapoporteb31d552018-10-30 15:08:04 -070017 p = memblock_alloc(size, 0);
Stephen Rothwell5669c3c2007-10-02 13:37:53 +100018 }
19 return p;
20}