net: kalmia: fix memory leaks [Linux 4.14.143]

This Linux kernel change "net: kalmia: fix memory leaks" is included in the Linux 4.14.143 release. This change is authored by Wenwen Wang <wenwen [at]> on Wed Aug 14 13:56:43 2019 -0500. The commit for this change in Linux stable tree is 849922a (patch) which is from upstream commit f1472cb. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream f1472cb.

net: kalmia: fix memory leaks

[ Upstream commit f1472cb09f11ddb41d4be84f0650835cb65a9073 ]

In kalmia_init_and_get_ethernet_addr(), 'usb_buf' is allocated through
kmalloc(). In the following execution, if the 'status' returned by
kalmia_send_init_packet() is not 0, 'usb_buf' is not deallocated, leading
to memory leaks. To fix this issue, add the 'out' label to free 'usb_buf'.

Signed-off-by: Wenwen Wang <>
Signed-off-by: David S. Miller <>
Signed-off-by: Sasha Levin <>

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/usb/kalmia.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index ce0b0b4..c677ec2 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -117,16 +117,16 @@
    status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
        / sizeof(init_msg_1[0]), usb_buf, 24);
    if (status != 0)
-       return status;
+       goto out;

    memcpy(usb_buf, init_msg_2, 12);
    status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
        / sizeof(init_msg_2[0]), usb_buf, 28);
    if (status != 0)
-       return status;
+       goto out;

    memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
    return status;

Leave a Reply

Your email address will not be published. Required fields are marked *