Re: [PATCH] [net-next] socket: fix unused-function warning

From: Arnd Bergmann
Date: Wed Jan 08 2020 - 16:41:08 EST


On Wed, Jan 8, 2020 at 10:27 PM David Miller <davem@xxxxxxxxxxxxx> wrote:
>
> From: Arnd Bergmann <arnd@xxxxxxxx>
> Date: Tue, 7 Jan 2020 22:35:59 +0100
>
> > 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]")
> > Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
>
> 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