Skip to contentSkip to conversation

mm: shmem: avoid build warning for CONFIG_SHMEM=n

PATCH Superseded Arnd Bergmann 3 participants 3 messages Dec 4, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: shmem: avoid build warning for CONFIG_SHMEM=n

From: Arnd Bergmann <[email protected]>

The newly added 'flags' variable is unused and causes a warning if CONFIG_SHMEM is disabled, since the shmem_acct_size() macro it is passed into does nothing:

mm/shmem.c: In function '__shmem_file_setup':
mm/shmem.c:5816:23: error: unused variable 'flags' [-Werror=unused-variable]
5816 | unsigned long flags = (vm_flags & VM_NORESERVE) ? SHMEM_F_NORESERVE : 0;
| ^~~~~

Replace the macro with an equivalent inline function to get the argument checking.

Fixes 6ff1610ced56 ("mm: shmem: use SHMEM_F_* flags instead of VM_* flags")
---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index 3f194c9842a8..93746270c459 100644
@@ -5794,7 +5794,7 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
 #define shmem_vm_ops				generic_file_vm_ops
 #define shmem_anon_vm_ops			generic_file_vm_ops
 #define shmem_file_operations			ramfs_file_operations
-#define shmem_acct_size(flags, size)		0
+static inline int shmem_acct_size(unsigned long flags, loff_t size) { return 0; }
 #define shmem_unacct_size(flags, size)		do {} while (0)
 
 static inline struct inode *shmem_get_inode(struct mnt_idmap *idmap,
Signature · 1 line
2.39.5
#1 lore raw

Hi Arnd,

Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added 'flags' variable is unused and causes a warning if CONFIG_SHMEM is disabled, since the shmem_acct_size() macro it is passed into does nothing:

mm/shmem.c: In function '__shmem_file_setup':
mm/shmem.c:5816:23: error: unused variable 'flags' [-Werror=unused-variable]
5816 | unsigned long flags = (vm_flags & VM_NORESERVE) ? SHMEM_F_NORESERVE : 0;
| ^~~~~

Quoted 5 lines

Replace the macro with an equivalent inline function to get the argument checking.

Fixes 6ff1610ced56 ("mm: shmem: use SHMEM_F_* flags instead of VM_* flags")

Thanks for the fix!

I recall that the kernel test robot also reported something similar, and Andrew sent out a fix for that [0]. But I guess it got dropped in the later re-rolls of the patchset.

Quoted 9 lines
---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +0 -0
index 3f194c9842a8..93746270c459 100644

mm/shmem.c EXPORT_SYMBOL_GPL(shmem_truncate_range); · line 5798

Quoted 6 lines
mm/shmem.c +1 -1
@@ -5794,7 +5794,7 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
 #define shmem_vm_ops				generic_file_vm_ops
 #define shmem_anon_vm_ops			generic_file_vm_ops
 #define shmem_file_operations			ramfs_file_operations
-#define shmem_acct_size(flags, size)		0
+static inline int shmem_acct_size(unsigned long flags, loff_t size) { return 0; }
 #define shmem_unacct_size(flags, size)		do {} while (0)

Can you please also make shmem_unacct_size() an inline function for consistency?

mm/shmem.c EXPORT_SYMBOL_GPL(shmem_truncate_range); · line 5800

Quoted 2 lines
mm/shmem.c +0 -0
 static inline struct inode *shmem_get_inode(struct mnt_idmap *idmap,

[0] https://lore.kernel.org/all/[email protected]/

Signature · 2 lines
Regards,
Pratyush Yadav
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added 'flags' variable is unused and causes a warning if CONFIG_SHMEM is disabled, since the shmem_acct_size() macro it is passed into does nothing:

mm/shmem.c: In function '__shmem_file_setup':
mm/shmem.c:5816:23: error: unused variable 'flags' [-Werror=unused-variable]
5816 | unsigned long flags = (vm_flags & VM_NORESERVE) ? SHMEM_F_NORESERVE : 0;
| ^~~~~

Quoted 5 lines

Replace the macro with an equivalent inline function to get the argument checking.

Fixes 6ff1610ced56 ("mm: shmem: use SHMEM_F_* flags instead of VM_* flags")

Thanks,
Pasha