Skip to contentSkip to conversation

char: nvram: Remove unused nvram_mutex to fix -Wunused-variable warning

PATCH In review Venkat Rao Bagalkote 3 participants 3 messages Mar 30 – Apr 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 char: nvram: Remove unused nvram_mutex to fix -Wunused-variable warning

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

warning: 'nvram_mutex' defined but not used [-Wunused-variable]

Remove the unused definition to avoid the warning.

---
v3:
- Removed global nvram_mutex entirely

 drivers/char/nvram.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/nvram.c +0 -1
index 9eff426a9286..9ab2744cd375 100644
@@ -53,7 +53,6 @@
 #include <asm/nvram.h>
 #endif
 
-static 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 */
Signature · 1 line
2.45.2
#1 lore raw
Quoted 7 lines · Venkat Rao Bagalkote

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

warning: 'nvram_mutex' defined but not used [-Wunused-variable]

Remove the unused definition to avoid the warning.

That is not the only reason for removing the nvram_mutex. I think we discussed in detail, why we think this can be removed here [1]. We should add those details in commit msg too.

Quoted 6 lines

---
v3:
- Removed global nvram_mutex entirely

We only removed the mutex definition and not the usage right. This does not look correct. Maybe you can check sashiko review comments for details -

https://sashiko.dev/#/patchset/20260330062201.2581-1-venkat88%40linux.ibm.com

-ritesh

Quoted 18 lines
 drivers/char/nvram.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/nvram.c +0 -1
index 9eff426a9286..9ab2744cd375 100644
@@ -53,7 +53,6 @@
 #include <asm/nvram.h>
 #endif
 
-static 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 */
Signature · 1 line
2.45.2
#2 lore raw
In reply to Venkat Rao Bagalkote
kernel test robot noticed the following build errors:

Hi Venkat,

kernel test robot noticed the following build errors:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus linus/master v7.0-rc6 next-20260402] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Venkat-Rao-Bagalkote/char-nvram-Remove-unused-nvram_mutex-to-fix-Wunused-variable-warning/20260330-234134
base:   char-misc/char-misc-testing
patch link:    https://lore.kernel.org/r/20260330062201.2581-1-venkat88%40linux.ibm.com
patch subject: [PATCH v3] char: nvram: Remove unused nvram_mutex to fix -Wunused-variable warning
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260402/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260402/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/char/nvram.c: In function 'nvram_misc_ioctl':

>> drivers/char/nvram.c:327:37: error: 'nvram_mutex' undeclared (first use in this function)
     327 |                         mutex_lock(&nvram_mutex);
         |                                     ^~~~~~~~~~~

drivers/char/nvram.c:327:37: note: each undeclared identifier is reported only once for each function it appears in

vim +/nvram_mutex +327 drivers/char/nvram.c

^1da177e4c3f41 Linus Torvalds      2005-04-16  278  
cb8d8006d43f22 Finn Thain          2019-01-15  279  static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
55929332c92e5d Arnd Bergmann       2010-04-27  280  			     unsigned long arg)
^1da177e4c3f41 Linus Torvalds      2005-04-16  281  {
2d58636e0af724 Finn Thain          2019-01-15  282  	long ret = -ENOTTY;
^1da177e4c3f41 Linus Torvalds      2005-04-16  283  
^1da177e4c3f41 Linus Torvalds      2005-04-16  284  	switch (cmd) {
95ac14b8a32817 Finn Thain          2019-01-15  285  #ifdef CONFIG_PPC
95ac14b8a32817 Finn Thain          2019-01-15  286  	case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
95ac14b8a32817 Finn Thain          2019-01-15  287  		pr_warn("nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
df561f6688fef7 Gustavo A. R. Silva 2020-08-23  288  		fallthrough;
95ac14b8a32817 Finn Thain          2019-01-15  289  	case IOC_NVRAM_GET_OFFSET:
95ac14b8a32817 Finn Thain          2019-01-15  290  		ret = -EINVAL;
95ac14b8a32817 Finn Thain          2019-01-15  291  #ifdef CONFIG_PPC_PMAC
95ac14b8a32817 Finn Thain          2019-01-15  292  		if (machine_is(powermac)) {
95ac14b8a32817 Finn Thain          2019-01-15  293  			int part, offset;
95ac14b8a32817 Finn Thain          2019-01-15  294  
95ac14b8a32817 Finn Thain          2019-01-15  295  			if (copy_from_user(&part, (void __user *)arg,
95ac14b8a32817 Finn Thain          2019-01-15  296  					   sizeof(part)) != 0)
95ac14b8a32817 Finn Thain          2019-01-15  297  				return -EFAULT;
95ac14b8a32817 Finn Thain          2019-01-15  298  			if (part < pmac_nvram_OF || part > pmac_nvram_NR)
95ac14b8a32817 Finn Thain          2019-01-15  299  				return -EINVAL;
95ac14b8a32817 Finn Thain          2019-01-15  300  			offset = pmac_get_partition(part);
20e07af71f34d9 Finn Thain          2019-01-15  301  			if (offset < 0)
20e07af71f34d9 Finn Thain          2019-01-15  302  				return -EINVAL;
95ac14b8a32817 Finn Thain          2019-01-15  303  			if (copy_to_user((void __user *)arg,
95ac14b8a32817 Finn Thain          2019-01-15  304  					 &offset, sizeof(offset)) != 0)
95ac14b8a32817 Finn Thain          2019-01-15  305  				return -EFAULT;
95ac14b8a32817 Finn Thain          2019-01-15  306  			ret = 0;
95ac14b8a32817 Finn Thain          2019-01-15  307  		}
95ac14b8a32817 Finn Thain          2019-01-15  308  #endif
95ac14b8a32817 Finn Thain          2019-01-15  309  		break;
20e07af71f34d9 Finn Thain          2019-01-15  310  #ifdef CONFIG_PPC32
95ac14b8a32817 Finn Thain          2019-01-15  311  	case IOC_NVRAM_SYNC:
95ac14b8a32817 Finn Thain          2019-01-15  312  		if (ppc_md.nvram_sync != NULL) {
95ac14b8a32817 Finn Thain          2019-01-15  313  			mutex_lock(&nvram_mutex);
95ac14b8a32817 Finn Thain          2019-01-15  314  			ppc_md.nvram_sync();
95ac14b8a32817 Finn Thain          2019-01-15  315  			mutex_unlock(&nvram_mutex);
95ac14b8a32817 Finn Thain          2019-01-15  316  		}
95ac14b8a32817 Finn Thain          2019-01-15  317  		ret = 0;
95ac14b8a32817 Finn Thain          2019-01-15  318  		break;
20e07af71f34d9 Finn Thain          2019-01-15  319  #endif
95ac14b8a32817 Finn Thain          2019-01-15  320  #elif defined(CONFIG_X86) || defined(CONFIG_M68K)
^1da177e4c3f41 Linus Torvalds      2005-04-16  321  	case NVRAM_INIT:
^1da177e4c3f41 Linus Torvalds      2005-04-16  322  		/* initialize NVRAM contents and checksum */
^1da177e4c3f41 Linus Torvalds      2005-04-16  323  		if (!capable(CAP_SYS_ADMIN))
^1da177e4c3f41 Linus Torvalds      2005-04-16  324  			return -EACCES;
^1da177e4c3f41 Linus Torvalds      2005-04-16  325  
2d58636e0af724 Finn Thain          2019-01-15  326  		if (arch_nvram_ops.initialize != NULL) {
613655fa39ff69 Arnd Bergmann       2010-06-02 @327  			mutex_lock(&nvram_mutex);
2d58636e0af724 Finn Thain          2019-01-15  328  			ret = arch_nvram_ops.initialize();
613655fa39ff69 Arnd Bergmann       2010-06-02  329  			mutex_unlock(&nvram_mutex);
2d58636e0af724 Finn Thain          2019-01-15  330  		}
2d58636e0af724 Finn Thain          2019-01-15  331  		break;
^1da177e4c3f41 Linus Torvalds      2005-04-16  332  	case NVRAM_SETCKS:
^1da177e4c3f41 Linus Torvalds      2005-04-16  333  		/* just set checksum, contents unchanged (maybe useful after
^1da177e4c3f41 Linus Torvalds      2005-04-16  334  		 * checksum garbaged somehow...) */
^1da177e4c3f41 Linus Torvalds      2005-04-16  335  		if (!capable(CAP_SYS_ADMIN))
^1da177e4c3f41 Linus Torvalds      2005-04-16  336  			return -EACCES;
^1da177e4c3f41 Linus Torvalds      2005-04-16  337  
2d58636e0af724 Finn Thain          2019-01-15  338  		if (arch_nvram_ops.set_checksum != NULL) {
613655fa39ff69 Arnd Bergmann       2010-06-02  339  			mutex_lock(&nvram_mutex);
2d58636e0af724 Finn Thain          2019-01-15  340  			ret = arch_nvram_ops.set_checksum();
613655fa39ff69 Arnd Bergmann       2010-06-02  341  			mutex_unlock(&nvram_mutex);
^1da177e4c3f41 Linus Torvalds      2005-04-16  342  		}
2d58636e0af724 Finn Thain          2019-01-15  343  		break;
95ac14b8a32817 Finn Thain          2019-01-15  344  #endif /* CONFIG_X86 || CONFIG_M68K */
2d58636e0af724 Finn Thain          2019-01-15  345  	}
2d58636e0af724 Finn Thain          2019-01-15  346  	return ret;
^1da177e4c3f41 Linus Torvalds      2005-04-16  347  }
^1da177e4c3f41 Linus Torvalds      2005-04-16  348  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki