From: Muhammad Bilal <meatuni001@gmail.com>
To: axboe@kernel.dk
Cc: hare@suse.de, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org,
Muhammad Bilal <meatuni001@gmail.com>
Subject: [PATCH] block: z2ram: fix dangling gendisk pointer on add_disk() failure
Date: Sun, 20 Sep 2026 00:20:33 +0500 [thread overview]
Message-ID: <20260919192033.271538-1-meatuni001@gmail.com> (raw)
z2ram_register_disk() stores the freshly allocated gendisk in
z2ram_gendisk[minor] before calling add_disk(). If add_disk() fails,
it drops the reference with put_disk() but leaves the array entry
pointing at the now-freed gendisk instead of clearing it.
z2_init() only aborts and unwinds when minor 0 fails; a later minor
failing just leaves that dangling entry in place and the module still
reports successful load. z2_exit() then unconditionally calls
del_gendisk()/put_disk() on every entry in z2ram_gendisk[], so module
removal walks into the stale pointer left behind by the earlier
failure.
Clear the array entry when add_disk() fails, and skip NULL entries in
z2_exit(), matching how a minor that never registered is represented.
Fixes: 76487f024142 ("z2ram: use separate gendisk for the different modes")
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
drivers/block/z2ram.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index b216cba1c3bf..e7fabaa53ba1 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -333,8 +333,10 @@ static int z2ram_register_disk(int minor)
z2ram_gendisk[minor] = disk;
err = add_disk(disk);
- if (err)
+ if (err) {
+ z2ram_gendisk[minor] = NULL;
put_disk(disk);
+ }
return err;
}
@@ -379,6 +381,8 @@ static void __exit z2_exit(void)
unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
for (i = 0; i < Z2MINOR_COUNT; i++) {
+ if (!z2ram_gendisk[i])
+ continue;
del_gendisk(z2ram_gendisk[i]);
put_disk(z2ram_gendisk[i]);
}
--
2.55.0
reply other threads:[~2026-09-19 19:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260919192033.271538-1-meatuni001@gmail.com \
--to=meatuni001@gmail.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.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®