* [PATCH] rpmsg: fix memory leak on channel
@ 2018-09-27 21:36 Colin King
2018-09-28 3:12 ` Bjorn Andersson
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2018-09-27 21:36 UTC (permalink / raw)
To: Ohad Ben-Cohen, Bjorn Andersson, linux-remoteproc
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
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: 53e2822e56c7 ("rpmsg: Introduce Qualcomm SMD backend")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/rpmsg/qcom_smd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 0dae7c9f4a8f..4abbeea782fa 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1122,8 +1122,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;
+ }
spin_lock_init(&channel->tx_lock);
spin_lock_init(&channel->recv_lock);
@@ -1173,6 +1175,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);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] rpmsg: fix memory leak on channel
2018-09-27 21:36 [PATCH] rpmsg: fix memory leak on channel Colin King
@ 2018-09-28 3:12 ` Bjorn Andersson
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Andersson @ 2018-09-28 3:12 UTC (permalink / raw)
To: Colin King
Cc: Ohad Ben-Cohen, linux-remoteproc, kernel-janitors, linux-kernel
On Thu 27 Sep 14:36 PDT 2018, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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: 53e2822e56c7 ("rpmsg: Introduce Qualcomm SMD backend")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Added Cc: stable and applied.
Thanks,
Bjorn
> ---
> drivers/rpmsg/qcom_smd.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
> index 0dae7c9f4a8f..4abbeea782fa 100644
> --- a/drivers/rpmsg/qcom_smd.c
> +++ b/drivers/rpmsg/qcom_smd.c
> @@ -1122,8 +1122,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;
> + }
>
> spin_lock_init(&channel->tx_lock);
> spin_lock_init(&channel->recv_lock);
> @@ -1173,6 +1175,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);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-09-28 3:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-27 21:36 [PATCH] rpmsg: fix memory leak on channel Colin King
2018-09-28 3:12 ` Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).