rpmsg: smd: fix memory leak on channel create
authorColin Ian King <colin.king@canonical.com>
Thu, 27 Sep 2018 21:36:27 +0000 (22:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2018 19:15:12 +0000 (11:15 -0800)
commit 940c620d6af8fca7d115de40f19870fba415efac 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: 53e2822e56c7 ("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>
drivers/rpmsg/qcom_smd.c

index f1a2147a6d842aafa997160f64dce76fd95c5e04..72d02bfeda9e90ddad5933fe2b41f093eb7081b8 100644 (file)
@@ -1049,8 +1049,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);
@@ -1099,6 +1101,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);