soc: mpfs: use kref cleanup on probe failure
Subsystems (3)
PATCH v2 1/1 soc: mpfs: use kref cleanup on probe failure
After kref_init(), the device_get_match_data() failure path frees the mailbox channel and sys_controller directly, bypassing the matching kref_put() for the initial reference.
Use mpfs_sys_controller_put() on this path so that the initial reference established by kref_init() is released through the existing kref release callback.
Rename the error label to reflect that cleanup is now performed through the kref helper.
This issue was found by manual code inspection.
---
v2:
- Add the missing Signed-off-by tag.
- Rename out_free_channel to out_put as suggested by Felix.
drivers/soc/microchip/mpfs-sys-controller.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +4 -3
@@ -159,7 +159,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) of_data = (struct mpfs_syscon_config *)device_get_match_data (dev);if (!of_data) { ret =dev_err_probe (dev, -EINVAL ,"Error getting match data\n" ); - goto out_free_channel; + goto out_put; }for (i =0 ; i < of_data->nb_subdevs; i++) {
@@ -173,8 +173,9 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)return 0 ; -out_free_channel: -mbox_free_channel (sys_controller->chan); +out_put: +mpfs_sys_controller_put (sys_controller); +return ret; out_free:kfree (sys_controller);return ret;
Signature · 1 line
2.43.0
Quoted 11 lines · Guangshuo Li
After
kref_init(), thedevice_get_match_data()failure path frees the mailbox channel andsys_controllerdirectly, bypassing the matchingkref_put()for the initial reference.Use
mpfs_sys_controller_put()on this path so that the initial reference established bykref_init()is released through the existing kref release callback.Rename the error label to reflect that cleanup is now performed through the kref helper.
Quoted 8 lines
This issue was found by manual code inspection.
Fixes 75ef23397558 ("soc: microchip: mpfs-sys-controller: fix resource leak on probe error")Signed-off-by Guangshuo Li <[email protected]>---
v2:
- Add the missing Signed-off-by tag.
- Renameout_free_channeltoout_putas suggested by Felix.
Applied, thanks.
Cheers,
Conor.
Quoted 32 lines
drivers/soc/microchip/mpfs-sys-controller.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/soc/microchip/mpfs-sys-controller.c +4
-3@@ -159,7 +159,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) of_data = (struct mpfs_syscon_config *)device_get_match_data (dev);if (!of_data) { ret =dev_err_probe (dev, -EINVAL ,"Error getting match data\n" ); - goto out_free_channel; + goto out_put; }for (i =0 ; i < of_data->nb_subdevs; i++) {@@ -173,8 +173,9 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)return 0 ; -out_free_channel: -mbox_free_channel (sys_controller->chan); +out_put: +mpfs_sys_controller_put (sys_controller); +return ret; out_free:kfree (sys_controller);return ret;Signature · 1 line
2.43.0
This patch was applied to riscv/linux.git (fixes) by Conor Dooley <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Conor Dooley <[email protected]>:
Quoted 9 lines · On Wed, 7 Oct 2026 20:17:43 +0800 you wrote:
After
kref_init(), thedevice_get_match_data()failure path frees the mailbox channel andsys_controllerdirectly, bypassing the matchingkref_put()for the initial reference.Use
mpfs_sys_controller_put()on this path so that the initial reference established bykref_init()is released through the existing kref release callback.[...]
Here is the summary with links:
- [v2] soc: mpfs: use kref cleanup on probe failure
https://git.kernel.org/riscv/c/6f77194e1147
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html