Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]
From: Christophe Leroy
Date: Wed Apr 03 2024 - 04:42:01 EST
Le 03/04/2024 à 10:06, Arnd Bergmann a écrit :
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> When CONFIG_NET is disabled, an extra warning shows up for this
> unused variable:
>
> lib/checksum_kunit.c:218:18: error: 'expected_csum_ipv6_magic' defined but not used [-Werror=unused-const-variable=]
>
> Hide it under the same #ifdef as the reference to it.
>
> Fixes: f24a70106dc1 ("lib: checksum: Fix build with CONFIG_NET=n")
I think that commit introduced unjustified #ifdef in a C file.
Refer
https://docs.kernel.org/process/coding-style.html#conditional-compilation
The fix should be:
diff --git a/lib/checksum_kunit.c b/lib/checksum_kunit.c
index bf70850035c7..1354953c8942 100644
--- a/lib/checksum_kunit.c
+++ b/lib/checksum_kunit.c
@@ -594,7 +594,6 @@ static void test_ip_fast_csum(struct kunit *test)
static void test_csum_ipv6_magic(struct kunit *test)
{
-#if defined(CONFIG_NET)
const struct in6_addr *saddr;
const struct in6_addr *daddr;
unsigned int len;
@@ -608,6 +607,9 @@ static void test_csum_ipv6_magic(struct kunit *test)
const int csum_offset = sizeof(struct in6_addr) + sizeof(struct
in6_addr) +
sizeof(int) + sizeof(char);
+ if (!IS_ENABLED(CONFIG_NET))
+ return;
+
for (int i = 0; i < NUM_IPv6_TESTS; i++) {
saddr = (const struct in6_addr *)(random_buf + i);
daddr = (const struct in6_addr *)(random_buf + i +
@@ -618,7 +620,6 @@ static void test_csum_ipv6_magic(struct kunit *test)
CHECK_EQ(to_sum16(expected_csum_ipv6_magic[i]),
csum_ipv6_magic(saddr, daddr, len, proto, csum));
}
-#endif /* !CONFIG_NET */
}
static struct kunit_case __refdata checksum_test_cases[] = {
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> lib/checksum_kunit.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/lib/checksum_kunit.c b/lib/checksum_kunit.c
> index bf70850035c7..80dd1e1b71ba 100644
> --- a/lib/checksum_kunit.c
> +++ b/lib/checksum_kunit.c
> @@ -215,6 +215,7 @@ static const u32 init_sums_no_overflow[] = {
> 0xffff0000, 0xfffffffb,
> };
>
> +#ifdef CONFIG_NET
> static const u16 expected_csum_ipv6_magic[] = {
> 0x18d4, 0x3085, 0x2e4b, 0xd9f4, 0xbdc8, 0x78f, 0x1034, 0x8422, 0x6fc0,
> 0xd2f6, 0xbeb5, 0x9d3, 0x7e2a, 0x312e, 0x778e, 0xc1bb, 0x7cf2, 0x9d1e,
> @@ -240,6 +241,7 @@ static const u16 expected_csum_ipv6_magic[] = {
> 0x99aa, 0xb06b, 0xee19, 0xcc2c, 0xf34c, 0x7c49, 0xdac3, 0xa71e, 0xc988,
> 0x3845, 0x1014
> };
> +#endif
>
> static const u16 expected_fast_csum[] = {
> 0xda83, 0x45da, 0x4f46, 0x4e4f, 0x34e, 0xe902, 0xa5e9, 0x87a5, 0x7187,