diff options
| author | Tejun Heo <tj@kernel.org> | 2024-07-30 09:30:11 -1000 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2024-07-30 09:30:11 -1000 |
| commit | c8faf11cd192214e231626c3ee973a35d8fc33f2 (patch) | |
| tree | 4c3fcfddf4c7c311e1856dbf4dac1240564731f1 /lib/overflow_kunit.c | |
| parent | sched_ext: Fixes incorrect type in bpf_scx_init() (diff) | |
| parent | Linux 6.11-rc1 (diff) | |
| download | linux-c8faf11cd192214e231626c3ee973a35d8fc33f2.tar.gz linux-c8faf11cd192214e231626c3ee973a35d8fc33f2.zip | |
Merge tag 'v6.11-rc1' into for-6.12
Linux 6.11-rc1
Diffstat (limited to 'lib/overflow_kunit.c')
| -rw-r--r-- | lib/overflow_kunit.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/overflow_kunit.c b/lib/overflow_kunit.c index 4ef31b0bb74d..f314a0c15a6d 100644 --- a/lib/overflow_kunit.c +++ b/lib/overflow_kunit.c @@ -1178,14 +1178,28 @@ struct foo { s16 array[] __counted_by(counter); }; +struct bar { + int a; + u32 counter; + s16 array[]; +}; + static void DEFINE_FLEX_test(struct kunit *test) { - DEFINE_RAW_FLEX(struct foo, two, array, 2); + /* Using _RAW_ on a __counted_by struct will initialize "counter" to zero */ + DEFINE_RAW_FLEX(struct foo, two_but_zero, array, 2); +#if __has_attribute(__counted_by__) + int expected_raw_size = sizeof(struct foo); +#else + int expected_raw_size = sizeof(struct foo) + 2 * sizeof(s16); +#endif + /* Without annotation, it will always be on-stack size. */ + DEFINE_RAW_FLEX(struct bar, two, array, 2); DEFINE_FLEX(struct foo, eight, array, counter, 8); DEFINE_FLEX(struct foo, empty, array, counter, 0); - KUNIT_EXPECT_EQ(test, __struct_size(two), - sizeof(struct foo) + sizeof(s16) + sizeof(s16)); + KUNIT_EXPECT_EQ(test, __struct_size(two_but_zero), expected_raw_size); + KUNIT_EXPECT_EQ(test, __struct_size(two), sizeof(struct bar) + 2 * sizeof(s16)); KUNIT_EXPECT_EQ(test, __struct_size(eight), 24); KUNIT_EXPECT_EQ(test, __struct_size(empty), sizeof(struct foo)); } @@ -1223,4 +1237,5 @@ static struct kunit_suite overflow_test_suite = { kunit_test_suite(overflow_test_suite); +MODULE_DESCRIPTION("Test cases for arithmetic overflow checks"); MODULE_LICENSE("Dual MIT/GPL"); |
