Skip to content

Commit 4f87032

Browse files
JoePerchesdavem330
authored andcommitted
s2io.c: Use calculated size in kmallocs
Use consistent style. Don't calculate the kmalloc size multiple times Signed-off-by: Joe Perches <[email protected]> Acked-by: Sreenivasa Honnur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 13d866a commit 4f87032

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

drivers/net/s2io.c

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -823,15 +823,15 @@ static int init_shared_mem(struct s2io_nic *nic)
823823
}
824824
mem_allocated += size;
825825
memset(tmp_v_addr, 0, size);
826+
827+
size = sizeof(struct rxd_info) *
828+
rxd_count[nic->rxd_mode];
826829
rx_blocks->block_virt_addr = tmp_v_addr;
827830
rx_blocks->block_dma_addr = tmp_p_addr;
828-
rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)*
829-
rxd_count[nic->rxd_mode],
830-
GFP_KERNEL);
831+
rx_blocks->rxds = kmalloc(size, GFP_KERNEL);
831832
if (!rx_blocks->rxds)
832833
return -ENOMEM;
833-
mem_allocated +=
834-
(sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
834+
mem_allocated += size;
835835
for (l=0; l<rxd_count[nic->rxd_mode];l++) {
836836
rx_blocks->rxds[l].virt_addr =
837837
rx_blocks->block_virt_addr +
@@ -867,41 +867,37 @@ static int init_shared_mem(struct s2io_nic *nic)
867867

868868
blk_cnt = rx_cfg->num_rxd /
869869
(rxd_count[nic->rxd_mode]+ 1);
870-
ring->ba = kmalloc((sizeof(struct buffAdd *) * blk_cnt),
871-
GFP_KERNEL);
870+
size = sizeof(struct buffAdd *) * blk_cnt;
871+
ring->ba = kmalloc(size, GFP_KERNEL);
872872
if (!ring->ba)
873873
return -ENOMEM;
874-
mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt);
874+
mem_allocated += size;
875875
for (j = 0; j < blk_cnt; j++) {
876876
int k = 0;
877-
ring->ba[j] =
878-
kmalloc((sizeof(struct buffAdd) *
879-
(rxd_count[nic->rxd_mode] + 1)),
880-
GFP_KERNEL);
877+
878+
size = sizeof(struct buffAdd) *
879+
(rxd_count[nic->rxd_mode] + 1);
880+
ring->ba[j] = kmalloc(size, GFP_KERNEL);
881881
if (!ring->ba[j])
882882
return -ENOMEM;
883-
mem_allocated += (sizeof(struct buffAdd) * \
884-
(rxd_count[nic->rxd_mode] + 1));
883+
mem_allocated += size;
885884
while (k != rxd_count[nic->rxd_mode]) {
886885
ba = &ring->ba[j][k];
887-
888-
ba->ba_0_org = (void *) kmalloc
889-
(BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
886+
size = BUF0_LEN + ALIGN_SIZE;
887+
ba->ba_0_org = kmalloc(size, GFP_KERNEL);
890888
if (!ba->ba_0_org)
891889
return -ENOMEM;
892-
mem_allocated +=
893-
(BUF0_LEN + ALIGN_SIZE);
890+
mem_allocated += size;
894891
tmp = (unsigned long)ba->ba_0_org;
895892
tmp += ALIGN_SIZE;
896893
tmp &= ~((unsigned long) ALIGN_SIZE);
897894
ba->ba_0 = (void *) tmp;
898895

899-
ba->ba_1_org = (void *) kmalloc
900-
(BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
896+
size = BUF1_LEN + ALIGN_SIZE;
897+
ba->ba_1_org = kmalloc(size, GFP_KERNEL);
901898
if (!ba->ba_1_org)
902899
return -ENOMEM;
903-
mem_allocated
904-
+= (BUF1_LEN + ALIGN_SIZE);
900+
mem_allocated += size;
905901
tmp = (unsigned long) ba->ba_1_org;
906902
tmp += ALIGN_SIZE;
907903
tmp &= ~((unsigned long) ALIGN_SIZE);
@@ -3835,23 +3831,22 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
38353831
u64 rx_mat;
38363832
u16 msi_control; /* Temp variable */
38373833
int ret, i, j, msix_indx = 1;
3834+
int size;
38383835

3839-
nic->entries = kmalloc(nic->num_entries * sizeof(struct msix_entry),
3840-
GFP_KERNEL);
3836+
size = nic->num_entries * sizeof(struct msix_entry);
3837+
nic->entries = kmalloc(size, GFP_KERNEL);
38413838
if (!nic->entries) {
38423839
DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
38433840
__func__);
38443841
nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
38453842
return -ENOMEM;
38463843
}
3847-
nic->mac_control.stats_info->sw_stat.mem_allocated
3848-
+= (nic->num_entries * sizeof(struct msix_entry));
3844+
nic->mac_control.stats_info->sw_stat.mem_allocated += size;
38493845

3850-
memset(nic->entries, 0, nic->num_entries * sizeof(struct msix_entry));
3846+
memset(nic->entries, 0, size);
38513847

3852-
nic->s2io_entries =
3853-
kmalloc(nic->num_entries * sizeof(struct s2io_msix_entry),
3854-
GFP_KERNEL);
3848+
size = nic->num_entries * sizeof(struct s2io_msix_entry);
3849+
nic->s2io_entries = kmalloc(size, GFP_KERNEL);
38553850
if (!nic->s2io_entries) {
38563851
DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
38573852
__func__);
@@ -3861,10 +3856,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
38613856
+= (nic->num_entries * sizeof(struct msix_entry));
38623857
return -ENOMEM;
38633858
}
3864-
nic->mac_control.stats_info->sw_stat.mem_allocated
3865-
+= (nic->num_entries * sizeof(struct s2io_msix_entry));
3866-
memset(nic->s2io_entries, 0,
3867-
nic->num_entries * sizeof(struct s2io_msix_entry));
3859+
nic->mac_control.stats_info->sw_stat.mem_allocated += size;
3860+
memset(nic->s2io_entries, 0, size);
38683861

38693862
nic->entries[0].entry = 0;
38703863
nic->s2io_entries[0].entry = 0;

0 commit comments

Comments
 (0)