summaryrefslogtreecommitdiffstats
path: root/drivers/soc/microchip
diff options
context:
space:
mode:
authorConor Dooley <conor.dooley@microchip.com>2022-03-18 17:21:08 +0000
committerArnd Bergmann <arnd@arndb.de>2022-03-18 22:30:43 +0100
commit8e145bc705e738ebe7ed6c53d93278981d9af356 (patch)
treec03c8150367450ede547ba1edf6728f050d872b2 /drivers/soc/microchip
parentc76edea0e52d5522835534de90c893ca50b04402 (diff)
downloadlinux-8e145bc705e738ebe7ed6c53d93278981d9af356.tar.bz2
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: d0054a470c33 ("soc: add microchip polarfire soc system controller") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Conor Dooley <mail@conchuod.ie> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'drivers/soc/microchip')
-rw-r--r--drivers/soc/microchip/mpfs-sys-controller.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c
index 2f4535929762..52291c231f0b 100644
--- a/drivers/soc/microchip/mpfs-sys-controller.c
+++ b/drivers/soc/microchip/mpfs-sys-controller.c
@@ -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);