Commit 4f870320 authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

s2io.c: Use calculated size in kmallocs

Use consistent style.  Don't calculate the kmalloc size multiple times
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarSreenivasa Honnur <sreenivasa.honnur@neterion.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 13d866a9
...@@ -823,15 +823,15 @@ static int init_shared_mem(struct s2io_nic *nic) ...@@ -823,15 +823,15 @@ static int init_shared_mem(struct s2io_nic *nic)
} }
mem_allocated += size; mem_allocated += size;
memset(tmp_v_addr, 0, size); memset(tmp_v_addr, 0, size);
size = sizeof(struct rxd_info) *
rxd_count[nic->rxd_mode];
rx_blocks->block_virt_addr = tmp_v_addr; rx_blocks->block_virt_addr = tmp_v_addr;
rx_blocks->block_dma_addr = tmp_p_addr; rx_blocks->block_dma_addr = tmp_p_addr;
rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)* rx_blocks->rxds = kmalloc(size, GFP_KERNEL);
rxd_count[nic->rxd_mode],
GFP_KERNEL);
if (!rx_blocks->rxds) if (!rx_blocks->rxds)
return -ENOMEM; return -ENOMEM;
mem_allocated += mem_allocated += size;
(sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
for (l=0; l<rxd_count[nic->rxd_mode];l++) { for (l=0; l<rxd_count[nic->rxd_mode];l++) {
rx_blocks->rxds[l].virt_addr = rx_blocks->rxds[l].virt_addr =
rx_blocks->block_virt_addr + rx_blocks->block_virt_addr +
...@@ -867,41 +867,37 @@ static int init_shared_mem(struct s2io_nic *nic) ...@@ -867,41 +867,37 @@ static int init_shared_mem(struct s2io_nic *nic)
blk_cnt = rx_cfg->num_rxd / blk_cnt = rx_cfg->num_rxd /
(rxd_count[nic->rxd_mode]+ 1); (rxd_count[nic->rxd_mode]+ 1);
ring->ba = kmalloc((sizeof(struct buffAdd *) * blk_cnt), size = sizeof(struct buffAdd *) * blk_cnt;
GFP_KERNEL); ring->ba = kmalloc(size, GFP_KERNEL);
if (!ring->ba) if (!ring->ba)
return -ENOMEM; return -ENOMEM;
mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt); mem_allocated += size;
for (j = 0; j < blk_cnt; j++) { for (j = 0; j < blk_cnt; j++) {
int k = 0; int k = 0;
ring->ba[j] =
kmalloc((sizeof(struct buffAdd) * size = sizeof(struct buffAdd) *
(rxd_count[nic->rxd_mode] + 1)), (rxd_count[nic->rxd_mode] + 1);
GFP_KERNEL); ring->ba[j] = kmalloc(size, GFP_KERNEL);
if (!ring->ba[j]) if (!ring->ba[j])
return -ENOMEM; return -ENOMEM;
mem_allocated += (sizeof(struct buffAdd) * \ mem_allocated += size;
(rxd_count[nic->rxd_mode] + 1));
while (k != rxd_count[nic->rxd_mode]) { while (k != rxd_count[nic->rxd_mode]) {
ba = &ring->ba[j][k]; ba = &ring->ba[j][k];
size = BUF0_LEN + ALIGN_SIZE;
ba->ba_0_org = (void *) kmalloc ba->ba_0_org = kmalloc(size, GFP_KERNEL);
(BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
if (!ba->ba_0_org) if (!ba->ba_0_org)
return -ENOMEM; return -ENOMEM;
mem_allocated += mem_allocated += size;
(BUF0_LEN + ALIGN_SIZE);
tmp = (unsigned long)ba->ba_0_org; tmp = (unsigned long)ba->ba_0_org;
tmp += ALIGN_SIZE; tmp += ALIGN_SIZE;
tmp &= ~((unsigned long) ALIGN_SIZE); tmp &= ~((unsigned long) ALIGN_SIZE);
ba->ba_0 = (void *) tmp; ba->ba_0 = (void *) tmp;
ba->ba_1_org = (void *) kmalloc size = BUF1_LEN + ALIGN_SIZE;
(BUF1_LEN + ALIGN_SIZE, GFP_KERNEL); ba->ba_1_org = kmalloc(size, GFP_KERNEL);
if (!ba->ba_1_org) if (!ba->ba_1_org)
return -ENOMEM; return -ENOMEM;
mem_allocated mem_allocated += size;
+= (BUF1_LEN + ALIGN_SIZE);
tmp = (unsigned long) ba->ba_1_org; tmp = (unsigned long) ba->ba_1_org;
tmp += ALIGN_SIZE; tmp += ALIGN_SIZE;
tmp &= ~((unsigned long) ALIGN_SIZE); tmp &= ~((unsigned long) ALIGN_SIZE);
...@@ -3835,23 +3831,22 @@ static int s2io_enable_msi_x(struct s2io_nic *nic) ...@@ -3835,23 +3831,22 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
u64 rx_mat; u64 rx_mat;
u16 msi_control; /* Temp variable */ u16 msi_control; /* Temp variable */
int ret, i, j, msix_indx = 1; int ret, i, j, msix_indx = 1;
int size;
nic->entries = kmalloc(nic->num_entries * sizeof(struct msix_entry), size = nic->num_entries * sizeof(struct msix_entry);
GFP_KERNEL); nic->entries = kmalloc(size, GFP_KERNEL);
if (!nic->entries) { if (!nic->entries) {
DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \ DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
__func__); __func__);
nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++; nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
return -ENOMEM; return -ENOMEM;
} }
nic->mac_control.stats_info->sw_stat.mem_allocated nic->mac_control.stats_info->sw_stat.mem_allocated += size;
+= (nic->num_entries * sizeof(struct msix_entry));
memset(nic->entries, 0, nic->num_entries * sizeof(struct msix_entry)); memset(nic->entries, 0, size);
nic->s2io_entries = size = nic->num_entries * sizeof(struct s2io_msix_entry);
kmalloc(nic->num_entries * sizeof(struct s2io_msix_entry), nic->s2io_entries = kmalloc(size, GFP_KERNEL);
GFP_KERNEL);
if (!nic->s2io_entries) { if (!nic->s2io_entries) {
DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
__func__); __func__);
...@@ -3861,10 +3856,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic) ...@@ -3861,10 +3856,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
+= (nic->num_entries * sizeof(struct msix_entry)); += (nic->num_entries * sizeof(struct msix_entry));
return -ENOMEM; return -ENOMEM;
} }
nic->mac_control.stats_info->sw_stat.mem_allocated nic->mac_control.stats_info->sw_stat.mem_allocated += size;
+= (nic->num_entries * sizeof(struct s2io_msix_entry)); memset(nic->s2io_entries, 0, size);
memset(nic->s2io_entries, 0,
nic->num_entries * sizeof(struct s2io_msix_entry));
nic->entries[0].entry = 0; nic->entries[0].entry = 0;
nic->s2io_entries[0].entry = 0; nic->s2io_entries[0].entry = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment