Skip to contentSkip to conversation

socket: fix unused-function warning

PATCH Superseded Arnd Bergmann 4 participants 5 messages Jan 7, 2020 – Jan 8, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 socket: fix unused-function warning

When procfs is disabled, the fdinfo code causes a harmless warning:

net/socket.c:1000:13: error: 'sock_show_fdinfo' defined but not used [-Werror=unused-function]
static void sock_show_fdinfo(struct seq_file *m, struct file *f)

Change the preprocessor conditional to a compiler conditional to avoid the warning and let the compiler throw away the function itself.

Fixes b4653342b151 ("net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]")
---
 net/socket.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/socket.c +1 -3
index 5230c9e1bdec..444a617819f0 100644
@@ -151,9 +151,7 @@ static const struct file_operations socket_file_ops = {
 	.sendpage =	sock_sendpage,
 	.splice_write = generic_splice_sendpage,
 	.splice_read =	sock_splice_read,
-#ifdef CONFIG_PROC_FS
-	.show_fdinfo =	sock_show_fdinfo,
-#endif
+	.show_fdinfo =	IS_ENABLED(CONFIG_PROC_FS) ? sock_show_fdinfo : NULL,
 };
 
 /*
Signature · 1 line
2.20.0
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arnd Bergmann

When procfs is disabled, the fdinfo code causes a harmless warning:

net/socket.c:1000:13: error: 'sock_show_fdinfo' defined but not used [-Werror=unused-function]
static void sock_show_fdinfo(struct seq_file *m, struct file *f)

Quoted 6 lines

Change the preprocessor conditional to a compiler conditional to avoid the warning and let the compiler throw away the function itself.

Fixes b4653342b151 ("net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]")

Thanks for fixing.

Quoted 20 lines
---
 net/socket.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/socket.c +1 -3
index 5230c9e1bdec..444a617819f0 100644
@@ -151,9 +151,7 @@ static const struct file_operations socket_file_ops = {
 	.sendpage =	sock_sendpage,
 	.splice_write = generic_splice_sendpage,
 	.splice_read =	sock_splice_read,
-#ifdef CONFIG_PROC_FS
-	.show_fdinfo =	sock_show_fdinfo,
-#endif
+	.show_fdinfo =	IS_ENABLED(CONFIG_PROC_FS) ? sock_show_fdinfo : NULL,
 };
 
 /*
maintainer
#2 lore raw
In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Tue, 7 Jan 2020 22:35:59 +0100

Quoted 6 lines

When procfs is disabled, the fdinfo code causes a harmless warning:

net/socket.c:1000:13: error: 'sock_show_fdinfo' defined but not used [-Werror=unused-function]
static void sock_show_fdinfo(struct seq_file *m, struct file *f)

Quoted 6 lines

Change the preprocessor conditional to a compiler conditional to avoid the warning and let the compiler throw away the function itself.

Fixes b4653342b151 ("net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]")

This isn't the prettiest thing I've ever seen.

I really think it's nicer to just explicitly put ifdef's around the forward declaration and the implementation of sock_show_fdinfo().

Alternatively, move the implementation up to the location of the forward declaration and then you just need one new ifdef guard.

#4 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann

When procfs is disabled, the fdinfo code causes a harmless warning:

net/socket.c:1000:13: error: 'sock_show_fdinfo' defined but not used [-Werror=unused-function]
static void sock_show_fdinfo(struct seq_file *m, struct file *f)

Change the preprocessor conditional to a compiler conditional to avoid the warning and let the compiler throw away the function itself.

Fixes b4653342b151 ("net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]")
---
 net/socket.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/socket.c +0 -0
index 5230c9e1bdec..444a617819f0 100644

net/socket.c static const struct file_operations socket_file_ops = { · line 155

Quoted 8 lines
net/socket.c +1 -3
@@ -151,9 +151,7 @@ static const struct file_operations socket_file_ops = {
 	.sendpage =	sock_sendpage,
 	.splice_write = generic_splice_sendpage,
 	.splice_read =	sock_splice_read,
-#ifdef CONFIG_PROC_FS
-	.show_fdinfo =	sock_show_fdinfo,
-#endif
+	.show_fdinfo =	IS_ENABLED(CONFIG_PROC_FS) ? sock_show_fdinfo : NULL,
 };

Ugh... So put that ifdef around the definition of sock_show_fdinfo, with #define sock_show_fdinfo NULL on the other side...

#3 lore raw
In reply to David Miller
Quoted 17 lines · David Miller

From: Arnd Bergmann <[email protected]>
Date: Tue, 7 Jan 2020 22:35:59 +0100

Quoted 6 lines

When procfs is disabled, the fdinfo code causes a harmless warning:

net/socket.c:1000:13: error: 'sock_show_fdinfo' defined but not used [-Werror=unused-function]
static void sock_show_fdinfo(struct seq_file *m, struct file *f)

Quoted 6 lines

Change the preprocessor conditional to a compiler conditional to avoid the warning and let the compiler throw away the function itself.

Fixes b4653342b151 ("net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]")
Quoted 7 lines

This isn't the prettiest thing I've ever seen.

I really think it's nicer to just explicitly put ifdef's around the forward declaration and the implementation of sock_show_fdinfo().

Alternatively, move the implementation up to the location of the forward declaration and then you just need one new ifdef guard.

My first version just had a __maybe_unused tag on the declaration, but I was hoping this would be nicer as it avoids the #ifdef.

I'll send the version Al suggested instead, unless you prefer the __maybe_unused.

Arnd