diff mbox series

[v2,net-next,3/6] lib/test_bitmap: verify intermediate arr32 when converting <-> bitmap

Message ID 20221018140027.48086-4-alexandr.lobakin@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series netlink: add universal 'bigint' attribute type | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 84 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexander Lobakin Oct. 18, 2022, 2 p.m. UTC
When testing converting bitmaps from/to arr32, use
bitmap_validate_arr32() to test whether the tail of the intermediate
array was cleared correctly. Previously there were checks only for
the actual bitmap generated with the double-conversion.
Note that we pass bitmap_arr32_size() instead of `sizeof(arr)`, as
we poison the bytes past the last used word with 0xa5s. Also, for
@nbits == 0, the validation function must return false, account that
case as well.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 lib/test_bitmap.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index a8005ad3bd58..c40ab3dfa776 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -605,6 +605,7 @@  static void __init test_bitmap_arr32(void)
 	unsigned int nbits, next_bit;
 	u32 arr[EXP1_IN_BITS / 32];
 	DECLARE_BITMAP(bmap2, EXP1_IN_BITS);
+	bool valid;
 
 	memset(arr, 0xa5, sizeof(arr));
 
@@ -620,6 +621,9 @@  static void __init test_bitmap_arr32(void)
 				" tail is not safely cleared: %d\n",
 				nbits, next_bit);
 
+		valid = bitmap_validate_arr32(arr, bitmap_arr32_size(nbits), nbits);
+		expect_eq_uint(!!nbits, valid);
+
 		if (nbits < EXP1_IN_BITS - 32)
 			expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
 								0xa5a5a5a5);