socket: fix unused-function warning
Subsystems (3)
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.
--- net/socket.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
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, };/*
Signature · 1 line
2.20.0
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 voidsock_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]")Signed-off-by Arnd Bergmann <[email protected]>
Thanks for fixing.
Quoted 20 lines
--- net/socket.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)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, };/*
David Miller
maintainerFrom: 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 voidsock_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]")Signed-off-by Arnd Bergmann <[email protected]>
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.
Quoted 17 lines · David Miller
From: Arnd Bergmann <[email protected]>
Date: Tue, 7 Jan 2020 22:35:59 +0100Quoted 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 voidsock_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]")Signed-off-by Arnd Bergmann <[email protected]>
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
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 voidsock_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]")Signed-off-by Arnd Bergmann <[email protected]>--- net/socket.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)net/socket.c +0
-0
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...