Skip to content

Commit

Permalink
rpmsg: smd: fix memory leak on channel create
Browse files Browse the repository at this point in the history
commit 940c620 upstream.

Currently a failed allocation of channel->name leads to an
immediate return without freeing channel. Fix this by setting
ret to -ENOMEM and jumping to an exit path that kfree's channel.

Detected by CoverityScan, CID#1473692 ("Resource Leak")

Fixes: 53e2822 ("rpmsg: Introduce Qualcomm SMD backend")
Cc: stable@vger.kernel.org
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Colin Ian King authored and Greg Kroah-Hartman committed Nov 13, 2018
1 parent 5fa09db commit 245af7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/rpmsg/qcom_smd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,10 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed

channel->edge = edge;
channel->name = kstrdup(name, GFP_KERNEL);
if (!channel->name)
return ERR_PTR(-ENOMEM);
if (!channel->name) {
ret = -ENOMEM;
goto free_channel;
}

mutex_init(&channel->tx_lock);
spin_lock_init(&channel->recv_lock);
Expand Down Expand Up @@ -1062,6 +1064,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed

free_name_and_channel:
kfree(channel->name);
free_channel:
kfree(channel);

return ERR_PTR(ret);
Expand Down

0 comments on commit 245af7e

Please sign in to comment.