diff options
author | John Johansen <john.johansen@canonical.com> | 2013-02-18 19:04:34 -0500 |
---|---|---|
committer | John Johansen <john.johansen@canonical.com> | 2013-04-28 03:36:09 -0400 |
commit | 0ca554b9fca425eb58325a36290deef698cef34b (patch) | |
tree | aa9cd7544db53f617f8bf6b0e441f97a55ed4181 /security/apparmor/lib.c | |
parent | 3cfcc19e0b5390c04cb5bfa4e8fde39395410e61 (diff) |
apparmor: add kvzalloc to handle zeroing for kvmalloc
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
Diffstat (limited to 'security/apparmor/lib.c')
-rw-r--r-- | security/apparmor/lib.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c index 7430298116d6..d6e1f2148398 100644 --- a/security/apparmor/lib.c +++ b/security/apparmor/lib.c | |||
@@ -75,15 +75,16 @@ void aa_info_message(const char *str) | |||
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * kvmalloc - do allocation preferring kmalloc but falling back to vmalloc | 78 | * __aa_kvmalloc - do allocation preferring kmalloc but falling back to vmalloc |
79 | * @size: size of allocation | 79 | * @size: how many bytes of memory are required |
80 | * @flags: the type of memory to allocate (see kmalloc). | ||
80 | * | 81 | * |
81 | * Return: allocated buffer or NULL if failed | 82 | * Return: allocated buffer or NULL if failed |
82 | * | 83 | * |
83 | * It is possible that policy being loaded from the user is larger than | 84 | * It is possible that policy being loaded from the user is larger than |
84 | * what can be allocated by kmalloc, in those cases fall back to vmalloc. | 85 | * what can be allocated by kmalloc, in those cases fall back to vmalloc. |
85 | */ | 86 | */ |
86 | void *kvmalloc(size_t size) | 87 | void *__aa_kvmalloc(size_t size, gfp_t flags) |
87 | { | 88 | { |
88 | void *buffer = NULL; | 89 | void *buffer = NULL; |
89 | 90 | ||
@@ -92,14 +93,17 @@ void *kvmalloc(size_t size) | |||
92 | 93 | ||
93 | /* do not attempt kmalloc if we need more than 16 pages at once */ | 94 | /* do not attempt kmalloc if we need more than 16 pages at once */ |
94 | if (size <= (16*PAGE_SIZE)) | 95 | if (size <= (16*PAGE_SIZE)) |
95 | buffer = kmalloc(size, GFP_NOIO | __GFP_NOWARN); | 96 | buffer = kmalloc(size, flags | GFP_NOIO | __GFP_NOWARN); |
96 | if (!buffer) { | 97 | if (!buffer) { |
97 | /* see kvfree for why size must be at least work_struct size | 98 | /* see kvfree for why size must be at least work_struct size |
98 | * when allocated via vmalloc | 99 | * when allocated via vmalloc |
99 | */ | 100 | */ |
100 | if (size < sizeof(struct work_struct)) | 101 | if (size < sizeof(struct work_struct)) |
101 | size = sizeof(struct work_struct); | 102 | size = sizeof(struct work_struct); |
102 | buffer = vmalloc(size); | 103 | if (flags & __GFP_ZERO) |
104 | buffer = vzalloc(size); | ||
105 | else | ||
106 | buffer = vmalloc(size); | ||
103 | } | 107 | } |
104 | return buffer; | 108 | return buffer; |
105 | } | 109 | } |