]> git.baikalelectronics.ru Git - kernel.git/commitdiff
caif: fix memory leak in cfctrl_linkup_request()
authorZhengchao Shao <shaozhengchao@huawei.com>
Wed, 4 Jan 2023 06:51:46 +0000 (14:51 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:58 +0000 (11:41 +0100)
[ Upstream commit fe69230f05897b3de758427b574fc98025dfc907 ]

When linktype is unknown or kzalloc failed in cfctrl_linkup_request(),
pkt is not released. Add release process to error path.

Fixes: 8906736d5768 ("net-caif: add CAIF core protocol stack")
Fixes: 237cbdd87db7 ("caif: Disconnect without waiting for response")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20230104065146.1153009-1-shaozhengchao@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/caif/cfctrl.c

index 2809cbd6b7f7478bad724214246d8141515ec488..d8cb4b2a076b4679d135d3e7b3ef40b6e24fbcef 100644 (file)
@@ -269,11 +269,15 @@ int cfctrl_linkup_request(struct cflayer *layer,
        default:
                pr_warn("Request setup of bad link type = %d\n",
                        param->linktype);
+               cfpkt_destroy(pkt);
                return -EINVAL;
        }
        req = kzalloc(sizeof(*req), GFP_KERNEL);
-       if (!req)
+       if (!req) {
+               cfpkt_destroy(pkt);
                return -ENOMEM;
+       }
+
        req->client_layer = user_layer;
        req->cmd = CFCTRL_CMD_LINK_SETUP;
        req->param = *param;