2024-04-03 08:20:17

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]

From: Arnd Bergmann <[email protected]>

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")
Signed-off-by: Arnd Bergmann <[email protected]>
---
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,
--
2.39.2



2024-04-03 08:42:38

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]



Le 03/04/2024 à 10:06, Arnd Bergmann a écrit :
> From: Arnd Bergmann <[email protected]>
>
> 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 <[email protected]>
> ---
> 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,

2024-04-03 09:25:43

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]

On Wed, Apr 3, 2024, at 10:41, Christophe Leroy wrote:
> Le 03/04/2024 à 10:06, Arnd Bergmann a écrit :
>> From: Arnd Bergmann <[email protected]>
>>
>> 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

2024-04-03 09:29:20

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]



Le 03/04/2024 à 10:58, Arnd Bergmann a écrit :
> On Wed, Apr 3, 2024, at 10:41, Christophe Leroy wrote:
>> Le 03/04/2024 à 10:06, Arnd Bergmann a écrit :
>>> From: Arnd Bergmann <[email protected]>
>>>
>>> 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.

FWIW, before replying I did a build check with pmac32_defconfig
(powerpc) with CONFIG_NET removed. I was able to build
lib/checksum_kunit.o and objdump shown there was no reference to
csum_ipv6_magic() inside it.

Christophe

2024-04-04 11:44:51

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 18/34] lib: checksum: hide unused expected_csum_ipv6_magic[]

On Wed, Apr 3, 2024, at 11:03, Christophe Leroy wrote:
> Le 03/04/2024 à 10:58, Arnd Bergmann a écrit :
>
>> On Wed, Apr 3, 2024, at 10:41, Christophe Leroy wrote:
>> 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.
>
> FWIW, before replying I did a build check with pmac32_defconfig
> (powerpc) with CONFIG_NET removed. I was able to build
> lib/checksum_kunit.o and objdump shown there was no reference to
> csum_ipv6_magic() inside it.

Right, got it now. I was confused a bit by CONFIG_NET vs CONFIG_IPV6
given that the common definition for csum_ipv6_magic() is in
net/ipv6 but unlike other files there still gets build when IPV6
is disabled but NET remains turned on.

I've done a little more randconfig testing to verify it,
sending v2 now.

Arnd