Skip to contentSkip to conversation

mm/mprotect: fix compilation warning because of unused 'mm' varaible

PATCH In review Mike Rapoport 2 participants 3 messages May 8, 2019 – May 13, 2019

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

PATCH 1/1 mm/mprotect: fix compilation warning because of unused 'mm' varaible

Since commit 0cbe3e26abe0 ("mm: update ptep_modify_prot_start/commit to take vm_area_struct as arg") the only place that uses the local 'mm' variable in change_pte_range() is the call to set_pte_at().

Many architectures define set_pte_at() as macro that does not use the 'mm' parameter, which generates the following compilation warning:

CC mm/mprotect.o
mm/mprotect.c: In function 'change_pte_range':
mm/mprotect.c:42:20: warning: unused variable 'mm' [-Wunused-variable]

  struct mm_struct *mm = vma->vm_mm;
                    ^~

Fix it by passing vma->mm to set_pte_at() and dropping the local 'mm' variable in change_pte_range().

---
 mm/mprotect.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mprotect.c +1 -2
index 028c724..61bfe24 100644
@@ -39,7 +39,6 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 		unsigned long addr, unsigned long end, pgprot_t newprot,
 		int dirty_accountable, int prot_numa)
 {
-	struct mm_struct *mm = vma->vm_mm;
 	pte_t *pte, oldpte;
 	spinlock_t *ptl;
 	unsigned long pages = 0;
@@ -136,7 +135,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 				newpte = swp_entry_to_pte(entry);
 				if (pte_swp_soft_dirty(oldpte))
 					newpte = pte_swp_mksoft_dirty(newpte);
-				set_pte_at(mm, addr, pte, newpte);
+				set_pte_at(vma->mm, addr, pte, newpte);
 
 				pages++;
 			}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 35 lines · Mike Rapoport

Since commit 0cbe3e26abe0 ("mm: update ptep_modify_prot_start/commit to take vm_area_struct as arg") the only place that uses the local 'mm' variable in change_pte_range() is the call to set_pte_at().

Many architectures define set_pte_at() as macro that does not use the 'mm' parameter, which generates the following compilation warning:

CC mm/mprotect.o
mm/mprotect.c: In function 'change_pte_range':
mm/mprotect.c:42:20: warning: unused variable 'mm' [-Wunused-variable]

  struct mm_struct *mm = vma->vm_mm;
                    ^~

Fix it by passing vma->mm to set_pte_at() and dropping the local 'mm' variable in change_pte_range().

---
 mm/mprotect.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mprotect.c +0 -1
index 028c724..61bfe24 100644
@@ -39,7 +39,6 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                unsigned long addr, unsigned long end, pgprot_t newprot,
                int dirty_accountable, int prot_numa)
 {
-       struct mm_struct *mm = vma->vm_mm;
        pte_t *pte, oldpte;
        spinlock_t *ptl;
        unsigned long pages = 0;

mm/mprotect.c static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, · line 138

Quoted 5 lines
mm/mprotect.c +1 -1
@@ -136,7 +135,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                                newpte = swp_entry_to_pte(entry);
                                if (pte_swp_soft_dirty(oldpte))
                                        newpte = pte_swp_mksoft_dirty(newpte);
-                               set_pte_at(mm, addr, pte, newpte);
+                               set_pte_at(vma->mm, addr, pte, newpte);

This should be vma->vm_mm.

Thanks,
Song

Quoted 6 lines
mm/mprotect.c +0 -1
                                pages++;
                        }
--

2.7.4

#2 lore raw
Quoted 36 lines · Song Liu
Quoted 34 lines · Mike Rapoport

Since commit 0cbe3e26abe0 ("mm: update ptep_modify_prot_start/commit to take vm_area_struct as arg") the only place that uses the local 'mm' variable in change_pte_range() is the call to set_pte_at().

Many architectures define set_pte_at() as macro that does not use the 'mm' parameter, which generates the following compilation warning:

CC mm/mprotect.o
mm/mprotect.c: In function 'change_pte_range':
mm/mprotect.c:42:20: warning: unused variable 'mm' [-Wunused-variable]

  struct mm_struct *mm = vma->vm_mm;
                    ^~

Fix it by passing vma->mm to set_pte_at() and dropping the local 'mm' variable in change_pte_range().

---
 mm/mprotect.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mprotect.c +0 -1
index 028c724..61bfe24 100644
@@ -39,7 +39,6 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                unsigned long addr, unsigned long end, pgprot_t newprot,
                int dirty_accountable, int prot_numa)
 {
-       struct mm_struct *mm = vma->vm_mm;
        pte_t *pte, oldpte;
        spinlock_t *ptl;
        unsigned long pages = 0;
Quoted 8 lines

mm/mprotect.c static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, · line 138

Quoted 6 lines
mm/mprotect.c +1 -1
@@ -136,7 +135,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                                newpte = swp_entry_to_pte(entry);
                                if (pte_swp_soft_dirty(oldpte))
                                        newpte = pte_swp_mksoft_dirty(newpte);
-                               set_pte_at(mm, addr, pte, newpte);
+                               set_pte_at(vma->mm, addr, pte, newpte);

This should be vma->vm_mm.

And we need to fix another reference to mm:

mm/mprotect.c +0 -0
index 8bdba81685d6..bf38dfbbb4b4 100644
@@ -135,7 +135,7 @@ static unsigned long change_pte_range(struct

vm_area_struct *vma, pmd_t *pmd,

                                newpte = swp_entry_to_pte(entry);
                                if (pte_swp_soft_dirty(oldpte))
                                        newpte = pte_swp_mksoft_dirty(newpte);

- set_pte_at(vma->mm, addr, pte, newpte);
+ set_pte_at(vma->vm_mm, addr, pte, newpte);

                                pages++;
                        }
@@ -149,7 +149,7 @@ static unsigned long change_pte_range(struct
vm_area_struct *vma, pmd_t *pmd,
                                 */
                                make_device_private_entry_read(&entry);
                                newpte = swp_entry_to_pte(entry);

- set_pte_at(mm, addr, pte, newpte);
+ set_pte_at(vma->vm_mm, addr, pte, newpte);

                                pages++;
                        }