[PATCH 1/1] initrd: use O_SYNC flag while opening /dev/ram for write

From: George Stark
Date: Mon Jul 08 2024 - 16:09:41 EST


initrd image is written to the /dev/ram block device using filp_open(),
kernel_write(). After fput() /dev/ram is mounted and may fail due to not
all data is actually written to the device yet. The mount error remains
hidden due to MS_SILENT flag usage and mount_root_generic has retries.
So use O_SYNC flag to have all data written to /dev/ram before mounting.

Signed-off-by: George Stark <gnstark@xxxxxxxxxxxxxxxxx>
---
init/do_mounts_rd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index ac021ae6e6fa..c9a4721c8362 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -195,7 +195,7 @@ int __init rd_load_image(char *from)
char rotator[4] = { '|' , '/' , '-' , '\\' };
#endif

- out_file = filp_open("/dev/ram", O_RDWR, 0);
+ out_file = filp_open("/dev/ram", O_RDWR | O_SYNC, 0);
if (IS_ERR(out_file))
goto out;

--
2.25.1