]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
staging: wilc1000: use kmemdup instead of kmalloc in add_network_to_shadow()
authorAjay Singh <ajay.kathat@microchip.com>
Fri, 11 May 2018 08:13:15 +0000 (13:43 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 May 2018 12:04:48 +0000 (14:04 +0200)
Use kmemdup instead of kmalloc & memcpy in add_network_to_shadow(). Also
added  code to set 'ies_len' to zero in case of memory allocation
failure.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c

index c730323cab8723ee5fa11275c93a64e3b19c5c7c..32bdefb91001de5d1e05965a965fa20a81cb53e7 100644 (file)
@@ -327,12 +327,15 @@ static void add_network_to_shadow(struct network_info *nw_info,
        shadow_nw_info->beacon_period = nw_info->beacon_period;
        shadow_nw_info->dtim_period = nw_info->dtim_period;
        shadow_nw_info->ch = nw_info->ch;
-       shadow_nw_info->ies_len = nw_info->ies_len;
        shadow_nw_info->tsf_hi = nw_info->tsf_hi;
        if (ap_found != -1)
                kfree(shadow_nw_info->ies);
-       shadow_nw_info->ies = kmalloc(nw_info->ies_len, GFP_KERNEL);
-       memcpy(shadow_nw_info->ies, nw_info->ies, nw_info->ies_len);
+       shadow_nw_info->ies = kmemdup(nw_info->ies, nw_info->ies_len,
+                                     GFP_KERNEL);
+       if (shadow_nw_info->ies)
+               shadow_nw_info->ies_len = nw_info->ies_len;
+       else
+               shadow_nw_info->ies_len = 0;
        shadow_nw_info->time_scan = jiffies;
        shadow_nw_info->time_scan_cached = jiffies;
        shadow_nw_info->found = 1;