Skip to contentSkip to conversation

soc: microchip: mpfs-sys-controller: fix resource leak on probe error

PATCH Applied Felix Gu 2 participants 2 messages May 6 – May 14

Subsystems (3)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 soc: microchip: mpfs-sys-controller: fix resource leak on probe error

In mpfs_sys_controller_probe(), when device_get_match_data() returns NULL, it returns -EINVAL directly without freeing the mbox channel or the allocated sys_controller memory, causing a resource leak.

Fixes 63b5305ad84d ("soc: microchip: mpfs-sys-controller: add support for pic64gx")
---
 drivers/soc/microchip/mpfs-sys-controller.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +4 -2
index 92d1142a59e6..0400a01b2338 100644
@@ -158,8 +158,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 = dev_err_probe(dev, -EINVAL, "Error getting match data\n");
+		goto out_free_channel;
 	}
 
 	for (i = 0; i < of_data->nb_subdevs; i++) {
@@ -173,6 +173,8 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
 
 	return 0;
 
+out_free_channel:
+	mbox_free_channel(sys_controller->chan);
 out_free:
 	kfree(sys_controller);
 	return ret;

---
base-commit: 9d0d467c3572e93c5faa2e5906a8bbcd70b24efd
change-id: 20260506-mpfs-c7e227663554

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
maintainer Applied
#1 lore raw

From: Conor Dooley <[email protected]>

Quoted 3 lines · Felix Gu

In mpfs_sys_controller_probe(), when device_get_match_data() returns NULL, it returns -EINVAL directly without freeing the mbox channel or the allocated sys_controller memory, causing a resource leak.

Applied to riscv-soc-fixes, thanks!

[1/1] soc: microchip: mpfs-sys-controller: fix resource leak on probe error

      https://git.kernel.org/conor/c/75ef23397558

Thanks,
Conor.