Skip to content

Commit

Permalink
lib/test_bitmap.c: do not accidentally use stack VLA
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Yury Norov <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Apr 11, 2018
1 parent 5f00ae0 commit f6f66c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/test_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,17 @@ static void __init test_bitmap_parselist(void)
}
}

#define EXP_BYTES (sizeof(exp) * 8)

static void __init test_bitmap_arr32(void)
{
unsigned int nbits, next_bit, len = sizeof(exp) * 8;
unsigned int nbits, next_bit;
u32 arr[sizeof(exp) / 4];
DECLARE_BITMAP(bmap2, len);
DECLARE_BITMAP(bmap2, EXP_BYTES);

memset(arr, 0xa5, sizeof(arr));

for (nbits = 0; nbits < len; ++nbits) {
for (nbits = 0; nbits < EXP_BYTES; ++nbits) {
bitmap_to_arr32(arr, exp, nbits);
bitmap_from_arr32(bmap2, arr, nbits);
expect_eq_bitmap(bmap2, exp, nbits);
Expand All @@ -316,7 +318,7 @@ static void __init test_bitmap_arr32(void)
" tail is not safely cleared: %d\n",
nbits, next_bit);

if (nbits < len - 32)
if (nbits < EXP_BYTES - 32)
expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
0xa5a5a5a5);
}
Expand Down

0 comments on commit f6f66c1

Please sign in to comment.