diff options
author | Kees Cook <keescook@chromium.org> | 2018-04-10 19:32:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-11 13:28:35 -0400 |
commit | f6f66c1bf53079ce1f0789c8b482fba35b81617d (patch) | |
tree | f6660b3a670c905f8f49e68ba6625c39be3bae56 /lib/test_bitmap.c | |
parent | 5f00ae0d3ef8d36041d8d40ec71ab31b22764cba (diff) |
lib/test_bitmap.c: do not accidentally use stack VLA
This avoids an accidental stack VLA (since the compiler thinks the value
of "len" can change, even when marked "const"). This just replaces it
with a #define so it will DTRT.
Seen with -Wvla. Fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621
Link: http://lkml.kernel.org/r/20180307212555.GA17927@beast
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Yury Norov <ynorov@caviumnetworks.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/test_bitmap.c')
-rw-r--r-- | lib/test_bitmap.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 413367cf569e..de16f7869fb1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c | |||
@@ -296,15 +296,17 @@ static void __init test_bitmap_parselist(void) | |||
296 | } | 296 | } |
297 | } | 297 | } |
298 | 298 | ||
299 | #define EXP_BYTES (sizeof(exp) * 8) | ||
300 | |||
299 | static void __init test_bitmap_arr32(void) | 301 | static void __init test_bitmap_arr32(void) |
300 | { | 302 | { |
301 | unsigned int nbits, next_bit, len = sizeof(exp) * 8; | 303 | unsigned int nbits, next_bit; |
302 | u32 arr[sizeof(exp) / 4]; | 304 | u32 arr[sizeof(exp) / 4]; |
303 | DECLARE_BITMAP(bmap2, len); | 305 | DECLARE_BITMAP(bmap2, EXP_BYTES); |
304 | 306 | ||
305 | memset(arr, 0xa5, sizeof(arr)); | 307 | memset(arr, 0xa5, sizeof(arr)); |
306 | 308 | ||
307 | for (nbits = 0; nbits < len; ++nbits) { | 309 | for (nbits = 0; nbits < EXP_BYTES; ++nbits) { |
308 | bitmap_to_arr32(arr, exp, nbits); | 310 | bitmap_to_arr32(arr, exp, nbits); |
309 | bitmap_from_arr32(bmap2, arr, nbits); | 311 | bitmap_from_arr32(bmap2, arr, nbits); |
310 | expect_eq_bitmap(bmap2, exp, nbits); | 312 | expect_eq_bitmap(bmap2, exp, nbits); |
@@ -316,7 +318,7 @@ static void __init test_bitmap_arr32(void) | |||
316 | " tail is not safely cleared: %d\n", | 318 | " tail is not safely cleared: %d\n", |
317 | nbits, next_bit); | 319 | nbits, next_bit); |
318 | 320 | ||
319 | if (nbits < len - 32) | 321 | if (nbits < EXP_BYTES - 32) |
320 | expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)], | 322 | expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)], |
321 | 0xa5a5a5a5); | 323 | 0xa5a5a5a5); |
322 | } | 324 | } |