misc: fastrpc: Fix an incomplete memory release in fastrpc_rpmsg_probe()
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 11 May 2020 16:27:22 +0000 (17:27 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:50:13 +0000 (17:50 +0200)
[ Upstream commit 0978de9fc7335c73934ab8fac189fb4cb3f23191 ]

fastrpc_channel_ctx is not freed if misc_register() fails, this would
lead to a memory leak. Fix this leak by adding kfree in misc_register()
error path.

Fixes: 278d56f970ae ("misc: fastrpc: Reference count channel context")
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20200511162722.2552-1-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/fastrpc.c

index 842f221..ee3291f 100644 (file)
@@ -1434,8 +1434,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
                                            domains[domain_id]);
        data->miscdev.fops = &fastrpc_fops;
        err = misc_register(&data->miscdev);
-       if (err)
+       if (err) {
+               kfree(data);
                return err;
+       }
 
        kref_init(&data->refcount);