From: Wentao Liang <vulab@iscas.ac.cn>
To: conor.dooley@microchip.com
Cc: daire.mcnamara@microchip.com, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] soc: microchip: mpfs: Fix flash leak in mpfs_sys_controller_probe()
Date: Thu, 17 Sep 2026 15:35:50 +0000 [thread overview]
Message-ID: <20260917153550.2160672-1-vulab@iscas.ac.cn> (raw)
of_get_mtd_device_by_node() returns an MTD device reference that the
caller has to drop with put_mtd_device(). The probe error paths return
without releasing it, and the reference stored in sys_controller->flash
is never dropped when the controller is destroyed either.
Release the flash on the probe error paths and in
mpfs_sys_controller_delete(), so the reference is always put.
Fixes: 742aa6c563d2 ("soc: microchip: mpfs: enable access to the system controller's flash")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/soc/microchip/mpfs-sys-controller.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c
index 92d1142a59e6..ad57b09e5807 100644
--- a/drivers/soc/microchip/mpfs-sys-controller.c
+++ b/drivers/soc/microchip/mpfs-sys-controller.c
@@ -98,6 +98,8 @@ static void mpfs_sys_controller_delete(struct kref *kref)
struct mpfs_sys_controller *sys_controller =
container_of(kref, struct mpfs_sys_controller, consumers);
+ if (sys_controller->flash)
+ put_mtd_device(sys_controller->flash);
mbox_free_channel(sys_controller->chan);
kfree(sys_controller);
}
@@ -159,7 +161,8 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
of_data = (struct mpfs_syscon_config *) device_get_match_data(dev);
if (!of_data) {
dev_err(dev, "Error getting match data\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_free;
}
for (i = 0; i < of_data->nb_subdevs; i++) {
@@ -174,6 +177,10 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
return 0;
out_free:
+ if (!IS_ERR_OR_NULL(sys_controller->flash))
+ put_mtd_device(sys_controller->flash);
+ if (!IS_ERR_OR_NULL(sys_controller->chan))
+ mbox_free_channel(sys_controller->chan);
kfree(sys_controller);
return ret;
}
--
2.34.1
next reply other threads:[~2026-09-17 15:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 15:35 Wentao Liang [this message]
2026-10-02 17:48 ` Conor Dooley
2026-10-08 13:18 ` Conor Dooley
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=20260917153550.2160672-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=conor.dooley@microchip.com \
--cc=daire.mcnamara@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=stable@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®