Mon Mar 2 02:26:37 2015 UTC ()
Fix broken error checking in kmalloc_array/kcalloc.


(riastradh)
diff -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/slab.h

cvs diff -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/Attic/slab.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/include/linux/Attic/slab.h 2014/07/16 20:59:58 1.4
+++ src/sys/external/bsd/drm2/include/linux/Attic/slab.h 2015/03/02 02:26:37 1.5
@@ -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
90static inline void * 90static inline void *
91kzalloc(size_t size, gfp_t gfp) 91kzalloc(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
96static inline void * 96static inline void *
97kmalloc_array(size_t n, size_t size, gfp_t gfp) 97kmalloc_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
104static inline void * 104static inline void *
105kcalloc(size_t n, size_t size, gfp_t gfp) 105kcalloc(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
112static inline void * 110static inline void *
113krealloc(void *ptr, size_t size, gfp_t gfp) 111krealloc(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
118static inline void 116static inline void
119kfree(void *ptr) 117kfree(void *ptr)
120{ 118{
121 if (ptr != NULL) 119 if (ptr != NULL)