diff mbox series

[19/34] sunrpc: suppress warnings for unused procfs functions

Message ID 20240403080702.3509288-20-arnd@kernel.org (mailing list archive)
State New
Headers show
Series address all -Wunused-const warnings | expand

Commit Message

Arnd Bergmann April 3, 2024, 8:06 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

There is a warning about unused variables when building with W=1 and no procfs:

net/sunrpc/cache.c:1660:30: error: 'cache_flush_proc_ops' defined but not used [-Werror=unused-const-variable=]
 1660 | static const struct proc_ops cache_flush_proc_ops = {
      |                              ^~~~~~~~~~~~~~~~~~~~
net/sunrpc/cache.c:1622:30: error: 'content_proc_ops' defined but not used [-Werror=unused-const-variable=]
 1622 | static const struct proc_ops content_proc_ops = {
      |                              ^~~~~~~~~~~~~~~~
net/sunrpc/cache.c:1598:30: error: 'cache_channel_proc_ops' defined but not used [-Werror=unused-const-variable=]
 1598 | static const struct proc_ops cache_channel_proc_ops = {
      |                              ^~~~~~~~~~~~~~~~~~~~~~

These are used inside of an #ifdef, so replacing that with an
IS_ENABLED() check lets the compiler see how they are used while
still dropping them during dead code elimination.

Fixes: dbf847ecb631 ("knfsd: allow cache_register to return error on failure")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/sunrpc/cache.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Jeffrey Layton April 3, 2024, 8:59 a.m. UTC | #1
On Wed, 2024-04-03 at 10:06 +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> There is a warning about unused variables when building with W=1 and no procfs:
> 
> net/sunrpc/cache.c:1660:30: error: 'cache_flush_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1660 | static const struct proc_ops cache_flush_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~~~~~
> net/sunrpc/cache.c:1622:30: error: 'content_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1622 | static const struct proc_ops content_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~
> net/sunrpc/cache.c:1598:30: error: 'cache_channel_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1598 | static const struct proc_ops cache_channel_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~~~~~~~
> 
> These are used inside of an #ifdef, so replacing that with an
> IS_ENABLED() check lets the compiler see how they are used while
> still dropping them during dead code elimination.
> 
> Fixes: dbf847ecb631 ("knfsd: allow cache_register to return error on failure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  net/sunrpc/cache.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> index 95ff74706104..ab3a57965dc0 100644
> --- a/net/sunrpc/cache.c
> +++ b/net/sunrpc/cache.c
> @@ -1673,12 +1673,14 @@ static void remove_cache_proc_entries(struct cache_detail *cd)
>  	}
>  }
>  
> -#ifdef CONFIG_PROC_FS
>  static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
>  {
>  	struct proc_dir_entry *p;
>  	struct sunrpc_net *sn;
>  
> +	if (!IS_ENABLED(CONFIG_PROC_FS))
> +		return 0;
> +
>  	sn = net_generic(net, sunrpc_net_id);
>  	cd->procfs = proc_mkdir(cd->name, sn->proc_net_rpc);
>  	if (cd->procfs == NULL)
> @@ -1706,12 +1708,6 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
>  	remove_cache_proc_entries(cd);
>  	return -ENOMEM;
>  }
> -#else /* CONFIG_PROC_FS */
> -static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
> -{
> -	return 0;
> -}
> -#endif
>  
>  void __init cache_initialize(void)
>  {

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Chuck Lever April 3, 2024, 1:20 p.m. UTC | #2
On Wed, Apr 03, 2024 at 04:06:37AM -0400, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> There is a warning about unused variables when building with W=1 and no procfs:
> 
> net/sunrpc/cache.c:1660:30: error: 'cache_flush_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1660 | static const struct proc_ops cache_flush_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~~~~~
> net/sunrpc/cache.c:1622:30: error: 'content_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1622 | static const struct proc_ops content_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~
> net/sunrpc/cache.c:1598:30: error: 'cache_channel_proc_ops' defined but not used [-Werror=unused-const-variable=]
>  1598 | static const struct proc_ops cache_channel_proc_ops = {
>       |                              ^~~~~~~~~~~~~~~~~~~~~~
> 
> These are used inside of an #ifdef, so replacing that with an
> IS_ENABLED() check lets the compiler see how they are used while
> still dropping them during dead code elimination.
> 
> Fixes: dbf847ecb631 ("knfsd: allow cache_register to return error on failure")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Chuck Lever <chuck.lever@oracle.com>


> ---
>  net/sunrpc/cache.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> index 95ff74706104..ab3a57965dc0 100644
> --- a/net/sunrpc/cache.c
> +++ b/net/sunrpc/cache.c
> @@ -1673,12 +1673,14 @@ static void remove_cache_proc_entries(struct cache_detail *cd)
>  	}
>  }
>  
> -#ifdef CONFIG_PROC_FS
>  static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
>  {
>  	struct proc_dir_entry *p;
>  	struct sunrpc_net *sn;
>  
> +	if (!IS_ENABLED(CONFIG_PROC_FS))
> +		return 0;
> +
>  	sn = net_generic(net, sunrpc_net_id);
>  	cd->procfs = proc_mkdir(cd->name, sn->proc_net_rpc);
>  	if (cd->procfs == NULL)
> @@ -1706,12 +1708,6 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
>  	remove_cache_proc_entries(cd);
>  	return -ENOMEM;
>  }
> -#else /* CONFIG_PROC_FS */
> -static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
> -{
> -	return 0;
> -}
> -#endif
>  
>  void __init cache_initialize(void)
>  {
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 95ff74706104..ab3a57965dc0 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1673,12 +1673,14 @@  static void remove_cache_proc_entries(struct cache_detail *cd)
 	}
 }
 
-#ifdef CONFIG_PROC_FS
 static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
 {
 	struct proc_dir_entry *p;
 	struct sunrpc_net *sn;
 
+	if (!IS_ENABLED(CONFIG_PROC_FS))
+		return 0;
+
 	sn = net_generic(net, sunrpc_net_id);
 	cd->procfs = proc_mkdir(cd->name, sn->proc_net_rpc);
 	if (cd->procfs == NULL)
@@ -1706,12 +1708,6 @@  static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
 	remove_cache_proc_entries(cd);
 	return -ENOMEM;
 }
-#else /* CONFIG_PROC_FS */
-static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
-{
-	return 0;
-}
-#endif
 
 void __init cache_initialize(void)
 {