@@ -1178,14 +1178,28 @@ struct foo {
1178
1178
s16 array [] __counted_by (counter );
1179
1179
};
1180
1180
1181
+ struct bar {
1182
+ int a ;
1183
+ u32 counter ;
1184
+ s16 array [];
1185
+ };
1186
+
1181
1187
static void DEFINE_FLEX_test (struct kunit * test )
1182
1188
{
1183
- DEFINE_RAW_FLEX (struct foo , two , array , 2 );
1189
+ /* Using _RAW_ on a __counted_by struct will initialize "counter" to zero */
1190
+ DEFINE_RAW_FLEX (struct foo , two_but_zero , array , 2 );
1191
+ #if __has_attribute (__counted_by__ )
1192
+ int expected_raw_size = sizeof (struct foo );
1193
+ #else
1194
+ int expected_raw_size = sizeof (struct foo ) + 2 * sizeof (s16 );
1195
+ #endif
1196
+ /* Without annotation, it will always be on-stack size. */
1197
+ DEFINE_RAW_FLEX (struct bar , two , array , 2 );
1184
1198
DEFINE_FLEX (struct foo , eight , array , counter , 8 );
1185
1199
DEFINE_FLEX (struct foo , empty , array , counter , 0 );
1186
1200
1187
- KUNIT_EXPECT_EQ (test , __struct_size (two ),
1188
- sizeof ( struct foo ) + sizeof (s16 ) + sizeof (s16 ));
1201
+ KUNIT_EXPECT_EQ (test , __struct_size (two_but_zero ), expected_raw_size );
1202
+ KUNIT_EXPECT_EQ ( test , __struct_size ( two ), sizeof (struct bar ) + 2 * sizeof (s16 ));
1189
1203
KUNIT_EXPECT_EQ (test , __struct_size (eight ), 24 );
1190
1204
KUNIT_EXPECT_EQ (test , __struct_size (empty ), sizeof (struct foo ));
1191
1205
}
0 commit comments