diff mbox series

[v4,7/8] mm: Use static initialisers for immutable fields of 'struct vm_fault'

Message ID 20210120173612.20913-8-will@kernel.org (mailing list archive)
State New, archived
Headers show
Series Create 'old' ptes for faultaround mappings on arm64 with hardware access flag | expand

Commit Message

Will Deacon Jan. 20, 2021, 5:36 p.m. UTC
In preparation for const-ifying the anonymous struct field of
'struct vm_fault', ensure that it is initialised using static
initialisers.

Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Will Deacon <will@kernel.org>
---
 mm/shmem.c    |  6 +++---
 mm/swapfile.c | 11 ++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

Comments

Nick Desaulniers Jan. 20, 2021, 6:21 p.m. UTC | #1
On Wed, Jan 20, 2021 at 9:36 AM Will Deacon <will@kernel.org> wrote:
>
> In preparation for const-ifying the anonymous struct field of
> 'struct vm_fault', ensure that it is initialised using static
> initialisers.

FWIW these are known as "designated initializers", ie.

struct foo my_foo = {
  .bar = 42,
};

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Will Deacon <will@kernel.org>
> ---
>  mm/shmem.c    |  6 +++---
>  mm/swapfile.c | 11 ++++++-----
>  2 files changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 7c6b6d8f6c39..1b254fbfdf52 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1520,11 +1520,11 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
>  {
>         struct vm_area_struct pvma;
>         struct page *page;
> -       struct vm_fault vmf;
> +       struct vm_fault vmf = {
> +               .vma = &pvma,
> +       };
>
>         shmem_pseudo_vma_init(&pvma, info, index);
> -       vmf.vma = &pvma;
> -       vmf.address = 0;
>         page = swap_cluster_readahead(swap, gfp, &vmf);
>         shmem_pseudo_vma_destroy(&pvma);
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 9fffc5af29d1..2b570a566276 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1951,8 +1951,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>         si = swap_info[type];
>         pte = pte_offset_map(pmd, addr);
>         do {
> -               struct vm_fault vmf;
> -
>                 if (!is_swap_pte(*pte))
>                         continue;
>
> @@ -1968,9 +1966,12 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>                 swap_map = &si->swap_map[offset];
>                 page = lookup_swap_cache(entry, vma, addr);
>                 if (!page) {
> -                       vmf.vma = vma;
> -                       vmf.address = addr;
> -                       vmf.pmd = pmd;
> +                       struct vm_fault vmf = {
> +                               .vma = vma,
> +                               .address = addr,
> +                               .pmd = pmd,
> +                       };
> +
>                         page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
>                                                 &vmf);
>                 }
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>


--
Thanks,
~Nick Desaulniers
Will Deacon Jan. 21, 2021, 12:50 p.m. UTC | #2
On Wed, Jan 20, 2021 at 10:21:33AM -0800, Nick Desaulniers wrote:
> On Wed, Jan 20, 2021 at 9:36 AM Will Deacon <will@kernel.org> wrote:
> >
> > In preparation for const-ifying the anonymous struct field of
> > 'struct vm_fault', ensure that it is initialised using static
> > initialisers.
> 
> FWIW these are known as "designated initializers", ie.
> 
> struct foo my_foo = {
>   .bar = 42,
> };
> 
> https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

Thanks, I'm useless with terminology. Will update.

Will
diff mbox series

Patch

diff --git a/mm/shmem.c b/mm/shmem.c
index 7c6b6d8f6c39..1b254fbfdf52 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1520,11 +1520,11 @@  static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
 {
 	struct vm_area_struct pvma;
 	struct page *page;
-	struct vm_fault vmf;
+	struct vm_fault vmf = {
+		.vma = &pvma,
+	};
 
 	shmem_pseudo_vma_init(&pvma, info, index);
-	vmf.vma = &pvma;
-	vmf.address = 0;
 	page = swap_cluster_readahead(swap, gfp, &vmf);
 	shmem_pseudo_vma_destroy(&pvma);
 
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 9fffc5af29d1..2b570a566276 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1951,8 +1951,6 @@  static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 	si = swap_info[type];
 	pte = pte_offset_map(pmd, addr);
 	do {
-		struct vm_fault vmf;
-
 		if (!is_swap_pte(*pte))
 			continue;
 
@@ -1968,9 +1966,12 @@  static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 		swap_map = &si->swap_map[offset];
 		page = lookup_swap_cache(entry, vma, addr);
 		if (!page) {
-			vmf.vma = vma;
-			vmf.address = addr;
-			vmf.pmd = pmd;
+			struct vm_fault vmf = {
+				.vma = vma,
+				.address = addr,
+				.pmd = pmd,
+			};
+
 			page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
 						&vmf);
 		}