diff mbox series

mm: ensure the uniformity of arguments passed to do_mmap(..)

Message ID 20250104063925.1544944-1-lsahn@ooseel.net (mailing list archive)
State New
Headers show
Series mm: ensure the uniformity of arguments passed to do_mmap(..) | expand

Commit Message

Leesoo Ahn Jan. 4, 2025, 6:39 a.m. UTC
Standardize the way of passing a value to @populate parameter of do_mmap(..)
as follow:

1. Caller must initialize the variable to 0, except it's clarified as
   the name of the variable, 'unused'.
2. do_mmap(..) doesn't take care of its initialization.

This patch has a couple of changes that:
- callers initialize the variable to 0.
- remove the line of initialization inside do_mmap(..)

Signed-off-by: Leesoo Ahn <lsahn@ooseel.net>
---
 mm/mmap.c  | 2 --
 mm/nommu.c | 2 --
 mm/util.c  | 2 +-
 3 files changed, 1 insertion(+), 5 deletions(-)

Comments

Matthew Wilcox Jan. 4, 2025, 4:45 p.m. UTC | #1
On Sat, Jan 04, 2025 at 03:39:25PM +0900, Leesoo Ahn wrote:
> Standardize the way of passing a value to @populate parameter of do_mmap(..)
> as follow:
> 
> 1. Caller must initialize the variable to 0, except it's clarified as
>    the name of the variable, 'unused'.
> 2. do_mmap(..) doesn't take care of its initialization.

Why?  This seems fragile.
diff mbox series

Patch

diff --git a/mm/mmap.c b/mm/mmap.c
index d32b7e701058..4aebb1440c35 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -289,8 +289,6 @@  unsigned long do_mmap(struct file *file, unsigned long addr,
 	struct mm_struct *mm = current->mm;
 	int pkey = 0;
 
-	*populate = 0;
-
 	if (!len)
 		return -EINVAL;
 
diff --git a/mm/nommu.c b/mm/nommu.c
index 9cb6e99215e2..fa69cd8271af 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1016,8 +1016,6 @@  unsigned long do_mmap(struct file *file,
 	int ret;
 	VMA_ITERATOR(vmi, current->mm, 0);
 
-	*populate = 0;
-
 	/* decide whether we should attempt the mapping, and if so what sort of
 	 * mapping */
 	ret = validate_mmap_request(file, addr, len, prot, flags, pgoff,
diff --git a/mm/util.c b/mm/util.c
index c1c3b06ab4f9..728effcab217 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -570,7 +570,7 @@  unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
-	unsigned long populate;
+	unsigned long populate = 0;
 	LIST_HEAD(uf);
 
 	ret = security_mmap_file(file, prot, flag);