Skip to contentSkip to conversation

mm: constify static mm_walk_ops

PATCH Applied Rikard Falkeborn 4 participants 7 messages Oct 14, 2021 – Oct 18, 2021

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

cover mm: constify static mm_walk_ops

Constify a few instances of static struct mm_walk_ops that are never modified. The only usage of them is to pass their address to walk_page_range() which has a pointer to const struct mm_walk_ops as argument. Making them const allows the compiler to put them in read-only memory.

Rikard Falkeborn (2):
mm/damon/vaddr: constify static mm_walk_ops
mm/memory_failure: constify static mm_walk_ops

 mm/damon/vaddr.c    | 4 ++--
 mm/memory-failure.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/2 mm/damon/vaddr: constify static mm_walk_ops

The only usage of these structs is to pass their addresses to walk_page_range(), which takes a pointer to const mm_walk_ops as argument. Make them const to allow the compiler to put them in read-only memory.

---
 mm/damon/vaddr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/vaddr.c +2 -2
index 953c145b4f08..65d4f115fa66 100644
@@ -476,7 +476,7 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr,
 	return 0;
 }
 
-static struct mm_walk_ops damon_mkold_ops = {
+static const struct mm_walk_ops damon_mkold_ops = {
 	.pmd_entry = damon_mkold_pmd_entry,
 };
 
@@ -572,7 +572,7 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr,
 	return 0;
 }
 
-static struct mm_walk_ops damon_young_ops = {
+static const struct mm_walk_ops damon_young_ops = {
 	.pmd_entry = damon_young_pmd_entry,
 };
 
Signature · 1 line
2.33.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mm/damon/vaddr: constify static mm_walk_ops

Quoted 6 lines · On Thu, 14 Oct 2021 09:50:41 +0200 Rikard Falkeborn…

The only usage of these structs is to pass their addresses to walk_page_range(), which takes a pointer to const mm_walk_ops as argument. Make them const to allow the compiler to put them in read-only memory.

Thanks,
SJ

[...]

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] mm/damon/vaddr: constify static mm_walk_ops

In reply to Rikard Falkeborn
Quoted 25 lines · Rikard Falkeborn

The only usage of these structs is to pass their addresses to walk_page_range(), which takes a pointer to const mm_walk_ops as argument. Make them const to allow the compiler to put them in read-only memory.

---
 mm/damon/vaddr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/vaddr.c +1 -1
index 953c145b4f08..65d4f115fa66 100644
@@ -476,7 +476,7 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr,
 	return 0;
 }
 
-static struct mm_walk_ops damon_mkold_ops = {
+static const struct mm_walk_ops damon_mkold_ops = {
 	.pmd_entry = damon_mkold_pmd_entry,
 };
 

mm/damon/vaddr.c static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr, · line 578

Quoted 8 lines
mm/damon/vaddr.c +1 -1
@@ -572,7 +572,7 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr,
 	return 0;
 }
 
-static struct mm_walk_ops damon_young_ops = {
+static const struct mm_walk_ops damon_young_ops = {
 	.pmd_entry = damon_young_pmd_entry,
 };
 
#4 lore raw

PATCH 2/2 mm/memory_failure: constify static mm_walk_ops

In reply to Rikard Falkeborn

The only usage of hwp_walk_ops is to pass its address to walk_page_range() which takes a pointer to const mm_walk_ops as argument. Make it const to allow the compiler to put it in read-only memory.

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
index 92eeb317adf4..8d5faf347ed1 100644
@@ -674,7 +674,7 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
 #define hwpoison_hugetlb_range	NULL
 #endif
 
-static struct mm_walk_ops hwp_walk_ops = {
+static const struct mm_walk_ops hwp_walk_ops = {
 	.pmd_entry = hwpoison_pte_range,
 	.hugetlb_entry = hwpoison_hugetlb_range,
 };
Signature · 1 line
2.33.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] mm/memory_failure: constify static mm_walk_ops

In reply to Rikard Falkeborn
Quoted 16 lines · Rikard Falkeborn

The only usage of hwp_walk_ops is to pass its address to walk_page_range() which takes a pointer to const mm_walk_ops as argument. Make it const to allow the compiler to put it in read-only memory.

---
 mm/memory-failure.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +0 -0
index 92eeb317adf4..8d5faf347ed1 100644

mm/memory-failure.c static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask, · line 680

Quoted 8 lines
mm/memory-failure.c +1 -1
@@ -674,7 +674,7 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
 #define hwpoison_hugetlb_range	NULL
 #endif
 
-static struct mm_walk_ops hwp_walk_ops = {
+static const struct mm_walk_ops hwp_walk_ops = {
 	.pmd_entry = hwpoison_pte_range,
 	.hugetlb_entry = hwpoison_hugetlb_range,
 };