mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Stecklina via B4 Relay <devnull+julian.stecklina.cyberus-technology.de@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Al Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Gao Xiang <xiang@kernel.org>,
	 linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-erofs@lists.ozlabs.org,
	 Julian Stecklina <julian.stecklina@cyberus-technology.de>
Subject: [PATCH v2 2/9] initrd: fix double fput for truncated ramdisks
Date: Sat, 22 Mar 2025 21:34:14 +0100	[thread overview]
Message-ID: <20250322-initrd-erofs-v2-2-d66ee4a2c756@cyberus-technology.de> (raw)
In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de>

From: Julian Stecklina <julian.stecklina@cyberus-technology.de>

When you actually take the exit via devblocks == 0, the code will do
fput(in_file) twice. This was introduced when the APIs where switched
to the file-based APIs.

Remove more of the multi-floppy support from the olden days.

Fixes: bef173299613 ("initrd: switch initrd loading to struct file based APIs")

Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
---
 init/do_mounts_rd.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 473f4f9417e157118b9a6e582607435484d53d63..d026df401afa0b7458ab1f266b21830aab974b92 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -234,20 +234,20 @@ int __init rd_load_image(char *from)
 		goto done;
 	}
 
+	if (devblocks < nblocks) {
+		printk(KERN_ERR "RAMDISK: looks truncated: (%luKiB vs %dKiB) - continuing anyway\n",
+		       devblocks, nblocks);
+		nblocks = devblocks;
+	}
+
 	buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
 	if (!buf) {
 		printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
 		goto done;
 	}
 
-	printk(KERN_NOTICE "RAMDISK: Loading %dKiB [%ld disk%s] into ram disk... ",
-		nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : "");
+	printk(KERN_NOTICE "RAMDISK: Loading %dKiB into ram disk... ", nblocks);
 	for (i = 0; i < nblocks; i++) {
-		if (i && (i % devblocks == 0)) {
-			pr_cont("done disk #1.\n");
-			fput(in_file);
-			break;
-		}
 		kernel_read(in_file, buf, BLOCK_SIZE, &in_pos);
 		kernel_write(out_file, buf, BLOCK_SIZE, &out_pos);
 	}

-- 
2.47.0



  parent reply	other threads:[~2025-03-22 20:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-22 20:34 [PATCH v2 0/9] initrd: cleanup and erofs support Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 1/9] initrd: remove ASCII spinner Julian Stecklina via B4 Relay
2025-03-25  6:42   ` David Disseldorp
2025-03-22 20:34 ` Julian Stecklina via B4 Relay [this message]
2025-03-22 20:34 ` [PATCH v2 3/9] initrd: add a generic mechanism to add fs detectors Julian Stecklina via B4 Relay
2025-03-24  9:35   ` Julian Stecklina
2025-03-22 20:34 ` [PATCH v2 4/9] fs: minix: register an initrd fs detector Julian Stecklina via B4 Relay
2025-03-22 23:26   ` kernel test robot
2025-03-22 20:34 ` [PATCH v2 5/9] fs: cramfs: " Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 6/9] fs: romfs: " Julian Stecklina via B4 Relay
2025-03-22 23:26   ` kernel test robot
2025-03-22 20:34 ` [PATCH v2 7/9] fs: squashfs: " Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 8/9] fs: ext2, ext4: " Julian Stecklina via B4 Relay
2025-03-22 23:36   ` kernel test robot
2025-03-22 20:34 ` [PATCH v2 9/9] fs: erofs: " Julian Stecklina via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250322-initrd-erofs-v2-2-d66ee4a2c756@cyberus-technology.de \
    --to=devnull+julian.stecklina.cyberus-technology.de@kernel.org \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=julian.stecklina@cyberus-technology.de \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®