From: Ma Ke <make24@iscas.ac.cn>
To: richard@nod.at, chengzhihao1@huawei.com,
miquel.raynal@bootlin.com, vigneshr@ti.com, logang@deltatee.com,
gregkh@linuxfoundation.org
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Ma Ke <make24@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] mtd: fix error handling in uif_init()
Date: Thu, 13 Mar 2025 17:16:09 +0800 [thread overview]
Message-ID: <20250313091609.308724-1-make24@iscas.ac.cn> (raw)
Once cdev_device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/mtd/ubi/build.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ef6a22f372f9..ca4c54cf9fd4 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -486,6 +486,7 @@ static int uif_init(struct ubi_device *ubi)
kill_volumes(ubi);
cdev_device_del(&ubi->cdev, &ubi->dev);
out_unreg:
+ put_device(&ubi->dev);
unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
ubi_err(ubi, "cannot initialize UBI %s, error %d",
ubi->ubi_name, err);
--
2.25.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2025-03-13 9:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 9:16 Ma Ke [this message]
2025-03-13 9:47 ` [PATCH] mtd: fix error handling in uif_init() Greg KH
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=20250313091609.308724-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=akpm@linux-foundation.org \
--cc=chengzhihao1@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=logang@deltatee.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--cc=vigneshr@ti.com \
/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