From: Zhengchao Shao Date: Wed, 4 Jan 2023 06:51:46 +0000 (+0800) Subject: caif: fix memory leak in cfctrl_linkup_request() X-Git-Tag: v5.15.92~478 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc1bc903970bdf63ca40ab923d3ccb765da9a8d9;p=platform%2Fkernel%2Flinux-rpi.git caif: fix memory leak in cfctrl_linkup_request() [ 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: b482cd2053e3 ("net-caif: add CAIF core protocol stack") Fixes: 8d545c8f958f ("caif: Disconnect without waiting for response") Signed-off-by: Zhengchao Shao Reviewed-by: Jiri Pirko Link: https://lore.kernel.org/r/20230104065146.1153009-1-shaozhengchao@huawei.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c index 2809cbd6..d8cb4b2 100644 --- a/net/caif/cfctrl.c +++ b/net/caif/cfctrl.c @@ -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;