Skip to contentSkip to conversation

selftests: net: af_unix: Fix a build error of unix_connect.c.

PATCH Superseded Kuniyuki Iwashima 2 participants 3 messages Jul 18, 2022 – Jul 20, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: net: af_unix: Fix a build error of unix_connect.c.

This patch fixes a build error reported in the link. [0]

unix_connect.c: In function ‘unix_connect_test’:
unix_connect.c:115:55: error: expected identifier before ‘(’ token

   #define offsetof(type, member) ((size_t)&((type *)0)->(member))
                                                       ^
  unix_connect.c:128:12: note: in expansion of macro ‘offsetof’
    addrlen = offsetof(struct sockaddr_un, sun_path) + variant->len;
              ^~~~~~~~

The checkpatch.pl will complain about this change, but the root cause of the build failure is that I fixed this in the v2 -> v3 change. [1]

CHECK: Macro argument 'member' may be better as '(member)' to avoid precedence issues #33: FILE: tools/testing/selftests/net/af_unix/unix_connect.c:115:
+#define offsetof(type, member) ((size_t)&((type *)0)->member)

[0]: https://lore.kernel.org/linux-mm/[email protected]/
[1]: https://lore.kernel.org/netdev/[email protected]/

Fixes e95ab1d85289 ("selftests: net: af_unix: Test connect() with different netns.")
---
 tools/testing/selftests/net/af_unix/unix_connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/af_unix/unix_connect.c +1 -1
index 157e44ef7f37..5b231d8c4683 100644
@@ -112,7 +112,7 @@ FIXTURE_TEARDOWN(unix_connect)
 		remove("test");
 }
 
-#define offsetof(type, member) ((size_t)&((type *)0)->(member))
+#define offsetof(type, member) ((size_t)&((type *)0)->member)
 
 TEST_F(unix_connect, test)
 {
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 9 lines · On Mon, 18 Jul 2022 09:23:50 -0700 Kuniyuki Iwashima wrote:

This patch fixes a build error reported in the link. [0]

unix_connect.c: In function ‘unix_connect_test’:
unix_connect.c:115:55: error: expected identifier before ‘(’ token

   #define offsetof(type, member) ((size_t)&((type *)0)->(member))
                                                       ^
  unix_connect.c:128:12: note: in expansion of macro ‘offsetof’
    addrlen = offsetof(struct sockaddr_un, sun_path) + variant->len;
              ^~~~~~~~

Can we delete this define and use stddef.h instead? man offsetof This is not kernel code the C standard lib is at our disposal.

Quoted 30 lines

The checkpatch.pl will complain about this change, but the root cause of the build failure is that I fixed this in the v2 -> v3 change. [1]

CHECK: Macro argument 'member' may be better as '(member)' to avoid precedence issues #33: FILE: tools/testing/selftests/net/af_unix/unix_connect.c:115:
+#define offsetof(type, member) ((size_t)&((type *)0)->member)

[0]: https://lore.kernel.org/linux-mm/[email protected]/
[1]: https://lore.kernel.org/netdev/[email protected]/

Fixes e95ab1d85289 ("selftests: net: af_unix: Test connect() with different netns.")
---
 tools/testing/selftests/net/af_unix/unix_connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/af_unix/unix_connect.c +1 -1
index 157e44ef7f37..5b231d8c4683 100644
@@ -112,7 +112,7 @@ FIXTURE_TEARDOWN(unix_connect)
 		remove("test");
 }
 
-#define offsetof(type, member) ((size_t)&((type *)0)->(member))
+#define offsetof(type, member) ((size_t)&((type *)0)->member)
 
 TEST_F(unix_connect, test)
 {
#2 lore raw
From:   Jakub Kicinski <[email protected]>
Date:   Tue, 19 Jul 2022 17:32:01 -0700
Quoted 11 lines · On Mon, 18 Jul 2022 09:23:50 -0700 Kuniyuki Iwashima wrote:
Quoted 9 lines

This patch fixes a build error reported in the link. [0]

unix_connect.c: In function ‘unix_connect_test’:
unix_connect.c:115:55: error: expected identifier before ‘(’ token

   #define offsetof(type, member) ((size_t)&((type *)0)->(member))
                                                       ^
  unix_connect.c:128:12: note: in expansion of macro ‘offsetof’
    addrlen = offsetof(struct sockaddr_un, sun_path) + variant->len;
              ^~~~~~~~
Quoted 2 lines

Can we delete this define and use stddef.h instead? man offsetof This is not kernel code the C standard lib is at our disposal.

Ah, it works.
I'll respin v2.

Thank you!