]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soc: microchip: mpfs-sys-controller: fix resource leak on probe error
authorFelix Gu <ustc.gu@gmail.com>
Wed, 6 May 2026 11:29:02 +0000 (19:29 +0800)
committerConor Dooley <conor.dooley@microchip.com>
Thu, 14 May 2026 20:03:34 +0000 (21:03 +0100)
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")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
drivers/soc/microchip/mpfs-sys-controller.c

index 92d1142a59e688894253080bbc9c22cc1f70a956..0400a01b2338dcc1617ef17c6c94e072521e842b 100644 (file)
@@ -158,8 +158,8 @@ no_flash:
 
        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 @@ no_flash:
 
        return 0;
 
+out_free_channel:
+       mbox_free_channel(sys_controller->chan);
 out_free:
        kfree(sys_controller);
        return ret;