Skip to content

Commit f3c0773

Browse files
JoePerchesdavem330
authored andcommitted
qlcnic: Convert vmalloc/memset to kcalloc
vmalloc is a limited resource. Don't use it unnecessarily. It seems this allocation should work with kcalloc. Remove unnecessary memset(,0,) of buf as it's completely overwritten as the previously only unset field in struct qlcnic_pci_func_cfg is now set to 0. Use kfree instead of vfree. Use ETH_ALEN instead of 6. Signed-off-by: Joe Perches <[email protected]> Acked-by: Jitendra Kalsaria <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 32e25cb commit f3c0773

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

drivers/net/ethernet/qlogic/qlcnic/qlcnic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ struct qlcnic_pci_func_cfg {
12671267
u16 port_num;
12681268
u8 pci_func;
12691269
u8 func_state;
1270-
u8 def_mac_addr[6];
1270+
u8 def_mac_addr[ETH_ALEN];
12711271
};
12721272

12731273
struct qlcnic_npar_func_cfg {

drivers/net/ethernet/qlogic/qlcnic/qlcnic_sysfs.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include <linux/slab.h>
9-
#include <linux/vmalloc.h>
109
#include <linux/interrupt.h>
1110

1211
#include "qlcnic.h"
@@ -927,38 +926,35 @@ static ssize_t qlcnic_sysfs_read_pci_config(struct file *file,
927926
u32 pci_func_count = qlcnic_get_pci_func_count(adapter);
928927
struct qlcnic_pci_func_cfg *pci_cfg;
929928
struct qlcnic_pci_info *pci_info;
930-
size_t pci_info_sz, pci_cfg_sz;
929+
size_t pci_cfg_sz;
931930
int i, ret;
932931

933932
pci_cfg_sz = pci_func_count * sizeof(*pci_cfg);
934933
if (size != pci_cfg_sz)
935934
return QL_STATUS_INVALID_PARAM;
936935

937-
pci_info_sz = pci_func_count * sizeof(*pci_info);
938-
pci_info = vmalloc(pci_info_sz);
936+
pci_info = kcalloc(pci_func_count, sizeof(*pci_info), GFP_KERNEL);
939937
if (!pci_info)
940938
return -ENOMEM;
941939

942-
memset(pci_info, 0, pci_info_sz);
943-
memset(buf, 0, pci_cfg_sz);
944-
pci_cfg = (struct qlcnic_pci_func_cfg *)buf;
945-
946940
ret = qlcnic_get_pci_info(adapter, pci_info);
947941
if (ret) {
948-
vfree(pci_info);
942+
kfree(pci_info);
949943
return ret;
950944
}
951945

946+
pci_cfg = (struct qlcnic_pci_func_cfg *)buf;
952947
for (i = 0; i < pci_func_count; i++) {
953948
pci_cfg[i].pci_func = pci_info[i].id;
954949
pci_cfg[i].func_type = pci_info[i].type;
950+
pci_cfg[i].func_state = 0;
955951
pci_cfg[i].port_num = pci_info[i].default_port;
956952
pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
957953
pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
958954
memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
959955
}
960956

961-
vfree(pci_info);
957+
kfree(pci_info);
962958
return size;
963959
}
964960

0 commit comments

Comments
 (0)