Skip to content

Commit 3d6423e

Browse files
chleroykuba-moo
authored andcommitted
kunit: Fix again checksum tests on big endian CPUs
Commit b38460b ("kunit: Fix checksum tests on big endian CPUs") fixed endianness issues with kunit checksum tests, but then commit 6f4c45c ("kunit: Add tests for csum_ipv6_magic and ip_fast_csum") introduced new issues on big endian CPUs. Those issues are once again reflected by the warnings reported by sparse. So, fix them with the same approach, perform proper conversion in order to support both little and big endian CPUs. Once the conversions are properly done and the right types used, the sparse warnings are cleared as well. Reported-by: Erhard Furtner <[email protected]> Fixes: 6f4c45c ("kunit: Add tests for csum_ipv6_magic and ip_fast_csum") Signed-off-by: Christophe Leroy <[email protected]> Tested-by: Charlie Jenkins <[email protected]> Tested-by: Guenter Roeck <[email protected]> Acked-by: Paolo Abeni <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/73df3a9e95c2179119398ad1b4c84cdacbd8dfb6.1708684443.git.christophe.leroy@csgroup.eu Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 244b96c commit 3d6423e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/checksum_kunit.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static const u32 init_sums_no_overflow[] = {
215215
0xffff0000, 0xfffffffb,
216216
};
217217

218-
static const __sum16 expected_csum_ipv6_magic[] = {
218+
static const u16 expected_csum_ipv6_magic[] = {
219219
0x18d4, 0x3085, 0x2e4b, 0xd9f4, 0xbdc8, 0x78f, 0x1034, 0x8422, 0x6fc0,
220220
0xd2f6, 0xbeb5, 0x9d3, 0x7e2a, 0x312e, 0x778e, 0xc1bb, 0x7cf2, 0x9d1e,
221221
0xca21, 0xf3ff, 0x7569, 0xb02e, 0xca86, 0x7e76, 0x4539, 0x45e3, 0xf28d,
@@ -241,7 +241,7 @@ static const __sum16 expected_csum_ipv6_magic[] = {
241241
0x3845, 0x1014
242242
};
243243

244-
static const __sum16 expected_fast_csum[] = {
244+
static const u16 expected_fast_csum[] = {
245245
0xda83, 0x45da, 0x4f46, 0x4e4f, 0x34e, 0xe902, 0xa5e9, 0x87a5, 0x7187,
246246
0x5671, 0xf556, 0x6df5, 0x816d, 0x8f81, 0xbb8f, 0xfbba, 0x5afb, 0xbe5a,
247247
0xedbe, 0xabee, 0x6aac, 0xe6b, 0xea0d, 0x67ea, 0x7e68, 0x8a7e, 0x6f8a,
@@ -577,7 +577,8 @@ static void test_csum_no_carry_inputs(struct kunit *test)
577577

578578
static void test_ip_fast_csum(struct kunit *test)
579579
{
580-
__sum16 csum_result, expected;
580+
__sum16 csum_result;
581+
u16 expected;
581582

582583
for (int len = IPv4_MIN_WORDS; len < IPv4_MAX_WORDS; len++) {
583584
for (int index = 0; index < NUM_IP_FAST_CSUM_TESTS; index++) {
@@ -586,7 +587,7 @@ static void test_ip_fast_csum(struct kunit *test)
586587
expected_fast_csum[(len - IPv4_MIN_WORDS) *
587588
NUM_IP_FAST_CSUM_TESTS +
588589
index];
589-
CHECK_EQ(expected, csum_result);
590+
CHECK_EQ(to_sum16(expected), csum_result);
590591
}
591592
}
592593
}
@@ -598,7 +599,7 @@ static void test_csum_ipv6_magic(struct kunit *test)
598599
const struct in6_addr *daddr;
599600
unsigned int len;
600601
unsigned char proto;
601-
unsigned int csum;
602+
__wsum csum;
602603

603604
const int daddr_offset = sizeof(struct in6_addr);
604605
const int len_offset = sizeof(struct in6_addr) + sizeof(struct in6_addr);
@@ -611,10 +612,10 @@ static void test_csum_ipv6_magic(struct kunit *test)
611612
saddr = (const struct in6_addr *)(random_buf + i);
612613
daddr = (const struct in6_addr *)(random_buf + i +
613614
daddr_offset);
614-
len = *(unsigned int *)(random_buf + i + len_offset);
615+
len = le32_to_cpu(*(__le32 *)(random_buf + i + len_offset));
615616
proto = *(random_buf + i + proto_offset);
616-
csum = *(unsigned int *)(random_buf + i + csum_offset);
617-
CHECK_EQ(expected_csum_ipv6_magic[i],
617+
csum = *(__wsum *)(random_buf + i + csum_offset);
618+
CHECK_EQ(to_sum16(expected_csum_ipv6_magic[i]),
618619
csum_ipv6_magic(saddr, daddr, len, proto, csum));
619620
}
620621
#endif /* !CONFIG_NET */

0 commit comments

Comments
 (0)