]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: wilc1000: use kmemdup in host_int_add_rx_gtk
authorChaehyun Lim <chaehyun.lim@gmail.com>
Sun, 8 Nov 2015 07:49:16 +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 0028bed54eaef293e5d57499a03f68d8d865ab19..51b6ddb821f76526e570c62e283b1e2bebb2940a 100644 (file)
@@ -3296,8 +3296,11 @@ int host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *rx_gtk,
                key_len += TX_MIC_KEY_LEN;
 
        if (key_rsc) {
-               msg.body.key_info.attr.wpa.seq = kmalloc(key_rsc_len, GFP_KERNEL);
-               memcpy(msg.body.key_info.attr.wpa.seq, key_rsc, key_rsc_len);
+               msg.body.key_info.attr.wpa.seq = kmemdup(key_rsc,
+                                                        key_rsc_len,
+                                                        GFP_KERNEL);
+               if (!msg.body.key_info.attr.wpa.seq)
+                       return -ENOMEM;
        }
 
        msg.id = HOST_IF_MSG_KEY;
@@ -3311,8 +3314,11 @@ int host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *rx_gtk,
        if (mode == STATION_MODE)
                msg.body.key_info.action = ADDKEY;
 
-       msg.body.key_info.attr.wpa.key = kmalloc(key_len, GFP_KERNEL);
-       memcpy(msg.body.key_info.attr.wpa.key, rx_gtk, gtk_key_len);
+       msg.body.key_info.attr.wpa.key = kmemdup(rx_gtk,
+                                                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,