Commit 8e145bc7 authored by Conor Dooley's avatar Conor Dooley Committed by Arnd Bergmann

soc/microchip: fix invalid free in mpfs_sys_controller_delete

Fix an invalid kfree in mpfs_sys_controller_delete, by replacing the
devm_kzalloc with a regular kzalloc. Change the error handling in the
probe function to free the sys_controller struct if the probe fails.

> cocci warnings: (new ones prefixed by >>)
> >> drivers/soc/microchip/mpfs-sys-controller.c:73:1-6: WARNING: invalid free of devm_ allocated data
Link: https://lore.kernel.org/linux-mm/202203180259.lgIylRZV-lkp@intel.com/

Fixes: d0054a47 ("soc: add microchip polarfire soc system controller")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarConor Dooley <conor.dooley@microchip.com>
Signed-off-by: default avatarConor Dooley <mail@conchuod.ie>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parent c76edea0
......@@ -96,9 +96,9 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct mpfs_sys_controller *sys_controller;
int i;
int i, ret;
sys_controller = devm_kzalloc(dev, sizeof(*sys_controller), GFP_KERNEL);
sys_controller = kzalloc(sizeof(*sys_controller), GFP_KERNEL);
if (!sys_controller)
return -ENOMEM;
......@@ -107,9 +107,12 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
sys_controller->client.tx_block = 1U;
sys_controller->chan = mbox_request_channel(&sys_controller->client, 0);
if (IS_ERR(sys_controller->chan))
return dev_err_probe(dev, PTR_ERR(sys_controller->chan),
"Failed to get mbox channel\n");
if (IS_ERR(sys_controller->chan)) {
ret = dev_err_probe(dev, PTR_ERR(sys_controller->chan),
"Failed to get mbox channel\n");
kfree(sys_controller);
return ret;
}
init_completion(&sys_controller->c);
kref_init(&sys_controller->consumers);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment