staging: wilc1000: fix memdup.cocci warnings
authorFengguang Wu <fengguang.wu@intel.com>
Mon, 26 Mar 2018 19:41:30 +0000 (21:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Mar 2018 11:39:21 +0000 (13:39 +0200)
drivers/staging/wilc1000/host_interface.c:946:32-39: WARNING opportunity for kmemdup
drivers/staging/wilc1000/host_interface.c:970:30-37: WARNING opportunity for kmemdup

 Use kmemdup rather than duplicating its implementation

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes: aaea2164bdff ("staging: wilc1000: check for kmalloc allocation failures")
CC: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wilc1000/host_interface.c

index 1b32e717099b35a70bb0c08feab5079d3deee39c..6b5300ca44a67a8bcd75a5ad0149504220a2984e 100644 (file)
@@ -936,12 +936,12 @@ static s32 handle_connect(struct wilc_vif *vif,
        }
 
        if (conn_attr->bssid) {
-               hif_drv->usr_conn_req.bssid = kmalloc(6, GFP_KERNEL);
+               hif_drv->usr_conn_req.bssid = kmemdup(conn_attr->bssid, 6,
+                                                     GFP_KERNEL);
                if (!hif_drv->usr_conn_req.bssid) {
                        result = -ENOMEM;
                        goto error;
                }
-               memcpy(hif_drv->usr_conn_req.bssid, conn_attr->bssid, 6);
        }
 
        hif_drv->usr_conn_req.ssid_len = conn_attr->ssid_len;
@@ -960,15 +960,13 @@ static s32 handle_connect(struct wilc_vif *vif,
 
        hif_drv->usr_conn_req.ies_len = conn_attr->ies_len;
        if (conn_attr->ies) {
-               hif_drv->usr_conn_req.ies = kmalloc(conn_attr->ies_len,
+               hif_drv->usr_conn_req.ies = kmemdup(conn_attr->ies,
+                                                   conn_attr->ies_len,
                                                    GFP_KERNEL);
                if (!hif_drv->usr_conn_req.ies) {
                        result = -ENOMEM;
                        goto error;
                }
-               memcpy(hif_drv->usr_conn_req.ies,
-                      conn_attr->ies,
-                      conn_attr->ies_len);
        }
 
        hif_drv->usr_conn_req.security = conn_attr->security;