Skip to contentSkip to conversation

init: fix init_dup

PATCH In review Christoph Hellwig 3 participants 4 messages Aug 3, 2020 – Aug 4, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: fix init_dup

Don't allocate an unused fd for each call. Also drop the extra reference from filp_open after the init_dup calls while we're at it.

Fixes 36e96b411649 ("init: add an init_dup helper")

Reported-by Stephen Rothwell <[email protected]>

---

Al, feel free to fold this into the original patch, as that is the last one in the branch.

 fs/init.c   | 2 +-
 init/main.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
fs/init.c +1 -1
index 730e05acda2392..e9c320a48cf157 100644
@@ -260,6 +260,6 @@ int __init init_dup(struct file *file)
 	fd = get_unused_fd_flags(0);
 	if (fd < 0)
 		return fd;
-	fd_install(get_unused_fd_flags(0), get_file(file));
+	fd_install(fd, get_file(file));
 	return 0;
 }
init/main.c +1 -0
index 089e21504b1fc1..9dae9c4f806bb9 100644
@@ -1470,6 +1470,7 @@ void __init console_on_rootfs(void)
 	init_dup(file);
 	init_dup(file);
 	init_dup(file);
+	fput(file);
 }
 
 static noinline void __init kernel_init_freeable(void)
Signature · 1 line
2.27.0
#1 lore raw

Hi Christoph,

Quoted 43 lines · On Mon, 3 Aug 2020 15:58:19 +0200 Christoph Hellwig <[email protected]> wrote:

Don't allocate an unused fd for each call. Also drop the extra reference from filp_open after the init_dup calls while we're at it.

Fixes 36e96b411649 ("init: add an init_dup helper")

Reported-by Stephen Rothwell <[email protected]>

---

Al, feel free to fold this into the original patch, as that is the last one in the branch.

 fs/init.c   | 2 +-
 init/main.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
fs/init.c +1 -1
index 730e05acda2392..e9c320a48cf157 100644
@@ -260,6 +260,6 @@ int __init init_dup(struct file *file)
 	fd = get_unused_fd_flags(0);
 	if (fd < 0)
 		return fd;
-	fd_install(get_unused_fd_flags(0), get_file(file));
+	fd_install(fd, get_file(file));
 	return 0;
 }
init/main.c +1 -0
index 089e21504b1fc1..9dae9c4f806bb9 100644
@@ -1470,6 +1470,7 @@ void __init console_on_rootfs(void)
 	init_dup(file);
 	init_dup(file);
 	init_dup(file);
+	fput(file);
 }
 
 static noinline void __init kernel_init_freeable(void)
Signature · 1 line
2.27.0

Thanks, I have added that to the vfs tree merge today.

Signature · 2 lines
Cheers,
Stephen Rothwell
#2 lore raw

Hi Christoph,

Quoted 41 lines · On Tue, 4 Aug 2020 09:53:54 +1000 Stephen Rothwell <[email protected]> wrote:
Quoted 39 lines · On Mon, 3 Aug 2020 15:58:19 +0200 Christoph Hellwig <[email protected]> wrote:

Don't allocate an unused fd for each call. Also drop the extra reference from filp_open after the init_dup calls while we're at it.

Fixes 36e96b411649 ("init: add an init_dup helper")

Reported-by Stephen Rothwell <[email protected]>

---

Al, feel free to fold this into the original patch, as that is the last one in the branch.

 fs/init.c   | 2 +-
 init/main.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
fs/init.c +1 -1
index 730e05acda2392..e9c320a48cf157 100644
@@ -260,6 +260,6 @@ int __init init_dup(struct file *file)
 	fd = get_unused_fd_flags(0);
 	if (fd < 0)
 		return fd;
-	fd_install(get_unused_fd_flags(0), get_file(file));
+	fd_install(fd, get_file(file));
 	return 0;
 }
init/main.c +1 -0
index 089e21504b1fc1..9dae9c4f806bb9 100644
@@ -1470,6 +1470,7 @@ void __init console_on_rootfs(void)
 	init_dup(file);
 	init_dup(file);
 	init_dup(file);
+	fput(file);
 }
 
Quoted 6 lines
Quoted 4 lines
init/main.c +0 -0
 static noinline void __init kernel_init_freeable(void)
Signature · 1 line
2.27.0

Thanks, I have added that to the vfs tree merge today.

This fixes my qemu problems, thanks.

Signature · 2 lines
Cheers,
Stephen Rothwell
maintainer
#3 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

Don't allocate an unused fd for each call. Also drop the extra reference from filp_open after the init_dup calls while we're at it.

Fixes 36e96b411649 ("init: add an init_dup helper")

Reported-by Stephen Rothwell <[email protected]>

---

Al, feel free to fold this into the original patch, as that is the last one in the branch.

Done and pushed, along with regenerated #for-next