[PATCH v2] char: nvram: Remove unused nvram_mutex to fix -Wunused-variable warning

Christophe Leroy (CS GROUP) chleroy at kernel.org
Mon Mar 23 21:14:31 AEDT 2026



Le 23/03/2026 à 08:32, Venkat Rao Bagalkote a écrit :
> v2:
>    - Added missing Suggested-by tag from Ritesh Harjani (IBM)
> 

Patch history must go _after_ the --- below, otherwise it will appear in 
the commit message when applied, which is pointless.

> drivers/char/nvram.c defines a static mutex 'nvram_mutex' which is never
> used. This results in a compiler warning on linux-next builds:

It is probably not only linux-next builds, I think the problem exists 
since 20e07af71f34 ("powerpc: Adopt nvram module for PPC64")

> 
>    warning: 'nvram_mutex' defined but not used [-Wunused-variable]
> 
> Remove the unused definition to avoid the warning.

It is not what you are doing.

You are just hiding the probleme by saying 'maybe it is used, maybe it 
is not used, I don't know I don't care". Please properly fix the problem 
instead.

I think the fix is probably to remove the #ifdef CONFIG_PPC32 around 
IOC_NVRAM_SYNC.
If you think it is important to return -ENOTTY on CONFIG_PPC64, just add:

diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 9eff426a9286..2fd744bf9093 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -308,8 +308,10 @@ static long nvram_misc_ioctl(struct file *file, 
unsigned int cmd,
  		}
  #endif
  		break;
-#ifdef CONFIG_PPC32
  	case IOC_NVRAM_SYNC:
+		if (IS_ENABLED(CONFIG_PPC64))
+			break;
+
  		if (ppc_md.nvram_sync != NULL) {
  			mutex_lock(&nvram_mutex);
  			ppc_md.nvram_sync();
@@ -317,7 +319,6 @@ static long nvram_misc_ioctl(struct file *file, 
unsigned int cmd,
  		}
  		ret = 0;
  		break;
-#endif
  #elif defined(CONFIG_X86) || defined(CONFIG_M68K)
  	case NVRAM_INIT:
  		/* initialize NVRAM contents and checksum */

> 
> Suggested-by: Ritesh Harjani (IBM) <ritesh.list at gmail.com>
> Signed-off-by: Venkat Rao Bagalkote <venkat88 at linux.ibm.com>
> ---
>   drivers/char/nvram.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
> index 9eff426a9286..2ce3307663ed 100644
> --- a/drivers/char/nvram.c
> +++ b/drivers/char/nvram.c
> @@ -53,7 +53,7 @@
>   #include <asm/nvram.h>
>   #endif
>   
> -static DEFINE_MUTEX(nvram_mutex);
> +static __maybe_unused DEFINE_MUTEX(nvram_mutex);
>   static DEFINE_SPINLOCK(nvram_state_lock);
>   static int nvram_open_cnt;	/* #times opened */
>   static int nvram_open_mode;	/* special open modes */



More information about the Linuxppc-dev mailing list