Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]
From: Arnd Bergmann
Date: Wed Apr 03 2024 - 04:58:36 EST
On Wed, Apr 3, 2024, at 10:41, Christophe Leroy wrote:
> 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:
>
> + 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 */
Yes, I usually prefer that approach, and I think I tried it first
but ran into compile-time problems because csum_ipv6_magic()
is declared conditionally. Let me try again, maybe I misremember
what I did or I can remove some more #ifdef checks for this.
Arnd