Skip to contentSkip to conversation

smaps: Fix defined but not used smaps_shmem_walk_ops

PATCH Applied Steven Price 2 participants 2 messages Apr 5, 2023

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

PATCH v2 1/1 smaps: Fix defined but not used smaps_shmem_walk_ops

When !CONFIG_SHMEM smaps_shmem_walk_ops is defined but not used, triggering a compiler warning. To avoid the warning remove the #ifdef around the usage. This has no effect because shmem_mapping() is a stub returning false when !CONFIG_SHMEM so the code will be compiled out, however we now need to also provide a stub for shmem_swap_usage().

Fixes 7b86ac3371b7 ("pagewalk: separate function pointers from iterator data")

---
I've implemented Jason's suggestion of removing the #ifdef around the usage and prodiving a stub for shmem_swap_usage() instead.

 fs/proc/task_mmu.c       | 3 +--
 include/linux/shmem_fs.h | 7 +++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
fs/proc/task_mmu.c +1 -2
index 6a96e1713fd5..cb49479acd2e 100644
@@ -782,7 +782,6 @@ static void smap_gather_stats(struct vm_area_struct *vma,
 	if (start >= vma->vm_end)
 		return;
 
-#ifdef CONFIG_SHMEM
 	if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) {
 		/*
 		 * For shared or readonly shmem mappings we know that all
@@ -803,7 +802,7 @@ static void smap_gather_stats(struct vm_area_struct *vma,
 			ops = &smaps_shmem_walk_ops;
 		}
 	}
-#endif
+
 	/* mmap_lock is held in m_start */
 	if (!start)
 		walk_page_vma(vma, ops, mss);
include/linux/shmem_fs.h +7 -0
index 103d1000a5a2..762c37b32bd4 100644
@@ -94,7 +94,14 @@ int shmem_unuse(unsigned int type);
 
 extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,
 			  struct mm_struct *mm, unsigned long vm_flags);
+#ifdef CONFIG_SHMEM
 extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
+#else
+static inline unsigned long shmem_swap_usage(struct vm_area_struct *vma)
+{
+	return 0;
+}
+#endif
 extern unsigned long shmem_partial_swap_usage(struct address_space *mapping,
 						pgoff_t start, pgoff_t end);
 
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Steven Price

When !CONFIG_SHMEM smaps_shmem_walk_ops is defined but not used, triggering a compiler warning. To avoid the warning remove the #ifdef around the usage. This has no effect because shmem_mapping() is a stub returning false when !CONFIG_SHMEM so the code will be compiled out, however we now need to also provide a stub for shmem_swap_usage().

Quoted 7 lines
Fixes 7b86ac3371b7 ("pagewalk: separate function pointers from iterator data")

---
I've implemented Jason's suggestion of removing the #ifdef around the usage and prodiving a stub for shmem_swap_usage() instead.

This seems OK

include/linux/shmem_fs.h int shmem_unuse(unsigned int type); · line 104

Quoted 10 lines

extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,

include/linux/shmem_fs.h +7 -0
 			  struct mm_struct *mm, unsigned long vm_flags);
+#ifdef CONFIG_SHMEM
 extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
+#else
+static inline unsigned long shmem_swap_usage(struct vm_area_struct *vma)
+{
+	return 0;
+}
+#endif

Though it would be nice if this file didn't have so many ifdef blocks

Jason