Skip to contentSkip to conversation

include: Silence gcc warning in linux_list.h

PATCH In review Phil Sutter 2 participants 4 messages Mar 25, 2022 – Mar 29, 2022 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/2 include: Silence gcc warning in linux_list.h

Compiler complained about empty prefetch() macro:

| ../include/linux_list.h:385:66: warning: right-hand operand of comma expression has no effect [-Wunused-value]
|   385 |         for (pos = list_entry((head)->next, typeof(*pos), member),      \
|       |                                                                  ^

Use nftables' variant instead which gcc seems to like more.

Fixes 36d2ed3de20a3 ("major cleanup of index2name infrastructure: use linux list (and fix leak in the nlif_close path)")
---
 include/linux_list.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux_list.h +1 -1
index de182a4764706..cf71837f18347 100644
@@ -29,7 +29,7 @@
 	1; \
 })
 
-#define prefetch(x)		1
+#define prefetch(x) ((void)0)
 
 /* empty define to make this work in userspace -HW */
 #ifndef smp_wmb
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH 2/2 libnfnetlink: Check getsockname() return code

The function may return -1 (and set errno). Assume it will leave addr_len value unchanged, so checking is necessary to not hide the error.

Fixes 4248314d40187 ("nfnl: fix compilation warning with gcc-4.7")
---
 src/libnfnetlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/libnfnetlink.c +4 -2
index 1cb6a820fee3d..667e5ef8f82a5 100644
@@ -210,7 +210,8 @@ struct nfnl_handle *nfnl_open(void)
 	nfnlh->peer.nl_family = AF_NETLINK;
 
 	addr_len = sizeof(nfnlh->local);
-	getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len);
+	if (getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len))
+		goto err_close;
 	if (addr_len != sizeof(nfnlh->local)) {
 		errno = EINVAL;
 		goto err_close;
@@ -231,7 +232,8 @@ struct nfnl_handle *nfnl_open(void)
 
 	/* use getsockname to get the netlink pid that the kernel assigned us */
 	addr_len = sizeof(nfnlh->local);
-	getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len);
+	if (getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len))
+		goto err_close;
 	if (addr_len != sizeof(nfnlh->local)) {
 		errno = EINVAL;
 		goto err_close;
Signature · 1 line
2.34.1
#2 lore raw

Re: [libnfnetlink PATCH 2/2] libnfnetlink: Check getsockname() return code

Quoted 3 lines · Phil Sutter

The function may return -1 (and set errno). Assume it will leave addr_len value unchanged, so checking is necessary to not hide the error.

LGTM.

Quoted 2 lines
Fixes 4248314d40187 ("nfnl: fix compilation warning with gcc-4.7")
#3 lore raw
In reply to Phil Sutter
Quoted 7 lines · Phil Sutter

Compiler complained about empty prefetch() macro:

| ../include/linux_list.h:385:66: warning: right-hand operand of comma expression has no effect [-Wunused-value]
|   385 |         for (pos = list_entry((head)->next, typeof(*pos), member),      \
|       |                                                                  ^

Use nftables' variant instead which gcc seems to like more.

LGTM, thanks

Quoted 2 lines
Fixes 36d2ed3de20a3 ("major cleanup of index2name infrastructure: use linux list (and fix leak in the nlif_close path)")