| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: slab.h,v 1.4 2014/07/16 20:59:58 riastradh Exp $ */ | | 1 | /* $NetBSD: slab.h,v 1.5 2015/03/02 02:26:37 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -86,36 +86,34 @@ kmalloc(size_t size, gfp_t gfp) | | | @@ -86,36 +86,34 @@ kmalloc(size_t size, gfp_t gfp) |
86 | { | | 86 | { |
87 | return malloc(size, M_TEMP, linux_gfp_to_malloc(gfp)); | | 87 | return malloc(size, M_TEMP, linux_gfp_to_malloc(gfp)); |
88 | } | | 88 | } |
89 | | | 89 | |
90 | static inline void * | | 90 | static inline void * |
91 | kzalloc(size_t size, gfp_t gfp) | | 91 | kzalloc(size_t size, gfp_t gfp) |
92 | { | | 92 | { |
93 | return malloc(size, M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO)); | | 93 | return malloc(size, M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO)); |
94 | } | | 94 | } |
95 | | | 95 | |
96 | static inline void * | | 96 | static inline void * |
97 | kmalloc_array(size_t n, size_t size, gfp_t gfp) | | 97 | kmalloc_array(size_t n, size_t size, gfp_t gfp) |
98 | { | | 98 | { |
99 | KASSERT(size != 0); | | 99 | if ((size != 0) && (n > (SIZE_MAX / size))) |
100 | KASSERT(n <= (SIZE_MAX / size)); | | 100 | return NULL; |
101 | return malloc((n * size), M_TEMP, linux_gfp_to_malloc(gfp)); | | 101 | return malloc((n * size), M_TEMP, linux_gfp_to_malloc(gfp)); |
102 | } | | 102 | } |
103 | | | 103 | |
104 | static inline void * | | 104 | static inline void * |
105 | kcalloc(size_t n, size_t size, gfp_t gfp) | | 105 | kcalloc(size_t n, size_t size, gfp_t gfp) |
106 | { | | 106 | { |
107 | if ((size == 0) && (n > (SIZE_MAX / size))) | | | |
108 | return NULL; | | | |
109 | return kmalloc_array(n, size, (gfp | __GFP_ZERO)); | | 107 | return kmalloc_array(n, size, (gfp | __GFP_ZERO)); |
110 | } | | 108 | } |
111 | | | 109 | |
112 | static inline void * | | 110 | static inline void * |
113 | krealloc(void *ptr, size_t size, gfp_t gfp) | | 111 | krealloc(void *ptr, size_t size, gfp_t gfp) |
114 | { | | 112 | { |
115 | return realloc(ptr, size, M_TEMP, linux_gfp_to_malloc(gfp)); | | 113 | return realloc(ptr, size, M_TEMP, linux_gfp_to_malloc(gfp)); |
116 | } | | 114 | } |
117 | | | 115 | |
118 | static inline void | | 116 | static inline void |
119 | kfree(void *ptr) | | 117 | kfree(void *ptr) |
120 | { | | 118 | { |
121 | if (ptr != NULL) | | 119 | if (ptr != NULL) |