staging: wilc1000: use kmemdup in host_int_add_ptk
authorChaehyun Lim <chaehyun.lim@gmail.com>
Sun, 8 Nov 2015 07:49:04 +0000 (16:49 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Dec 2015 22:14:03 +0000 (14:14 -0800)
This patch changes kmalloc followed by memcpy to kmemdup
The error checking is also added when kmemdup is failed.

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wilc1000/host_interface.c

index dd7e8edb850ddd047fe55ee75d7264fa3b9e5a58..18623c7b99da5bb72c5dc1a2659d9455bf430a77 100644 (file)
@@ -3239,8 +3239,9 @@ int host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *ptk,
        if (mode == STATION_MODE)
                msg.body.key_info.action = ADDKEY;
 
-       msg.body.key_info.attr.wpa.key = kmalloc(ptk_key_len, GFP_KERNEL);
-       memcpy(msg.body.key_info.attr.wpa.key, ptk, ptk_key_len);
+       msg.body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
+       if (!msg.body.key_info.attr.wpa.key)
+               return -ENOMEM;
 
        if (rx_mic) {
                memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic, RX_MIC_KEY_LEN);