diff options
author | Joe Perches <joe@perches.com> | 2009-08-24 13:29:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-08-31 01:34:43 -0400 |
commit | 4f87032021be1aa0c3bb66b0c89d30cb35b57f8f (patch) | |
tree | e74a4870d18c7288a484836bb4211deb11a36b9f /drivers/net/s2io.c | |
parent | 13d866a9c912d6bc7133f4ef4d536c3a960b06cb (diff) |
s2io.c: Use calculated size in kmallocs
Use consistent style. Don't calculate the kmalloc size multiple times
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Sreenivasa Honnur <sreenivasa.honnur@neterion.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/s2io.c')
-rw-r--r-- | drivers/net/s2io.c | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c index b6bd3c812adb..75f2209bc013 100644 --- a/drivers/net/s2io.c +++ b/drivers/net/s2io.c | |||
@@ -823,15 +823,15 @@ static int init_shared_mem(struct s2io_nic *nic) | |||
823 | } | 823 | } |
824 | mem_allocated += size; | 824 | mem_allocated += size; |
825 | memset(tmp_v_addr, 0, size); | 825 | memset(tmp_v_addr, 0, size); |
826 | |||
827 | size = sizeof(struct rxd_info) * | ||
828 | rxd_count[nic->rxd_mode]; | ||
826 | rx_blocks->block_virt_addr = tmp_v_addr; | 829 | rx_blocks->block_virt_addr = tmp_v_addr; |
827 | rx_blocks->block_dma_addr = tmp_p_addr; | 830 | rx_blocks->block_dma_addr = tmp_p_addr; |
828 | rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)* | 831 | rx_blocks->rxds = kmalloc(size, GFP_KERNEL); |
829 | rxd_count[nic->rxd_mode], | ||
830 | GFP_KERNEL); | ||
831 | if (!rx_blocks->rxds) | 832 | if (!rx_blocks->rxds) |
832 | return -ENOMEM; | 833 | return -ENOMEM; |
833 | mem_allocated += | 834 | mem_allocated += size; |
834 | (sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]); | ||
835 | for (l=0; l<rxd_count[nic->rxd_mode];l++) { | 835 | for (l=0; l<rxd_count[nic->rxd_mode];l++) { |
836 | rx_blocks->rxds[l].virt_addr = | 836 | rx_blocks->rxds[l].virt_addr = |
837 | rx_blocks->block_virt_addr + | 837 | rx_blocks->block_virt_addr + |
@@ -867,41 +867,37 @@ static int init_shared_mem(struct s2io_nic *nic) | |||
867 | 867 | ||
868 | blk_cnt = rx_cfg->num_rxd / | 868 | blk_cnt = rx_cfg->num_rxd / |
869 | (rxd_count[nic->rxd_mode]+ 1); | 869 | (rxd_count[nic->rxd_mode]+ 1); |
870 | ring->ba = kmalloc((sizeof(struct buffAdd *) * blk_cnt), | 870 | size = sizeof(struct buffAdd *) * blk_cnt; |
871 | GFP_KERNEL); | 871 | ring->ba = kmalloc(size, GFP_KERNEL); |
872 | if (!ring->ba) | 872 | if (!ring->ba) |
873 | return -ENOMEM; | 873 | return -ENOMEM; |
874 | mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt); | 874 | mem_allocated += size; |
875 | for (j = 0; j < blk_cnt; j++) { | 875 | for (j = 0; j < blk_cnt; j++) { |
876 | int k = 0; | 876 | int k = 0; |
877 | ring->ba[j] = | 877 | |
878 | kmalloc((sizeof(struct buffAdd) * | 878 | size = sizeof(struct buffAdd) * |
879 | (rxd_count[nic->rxd_mode] + 1)), | 879 | (rxd_count[nic->rxd_mode] + 1); |
880 | GFP_KERNEL); | 880 | ring->ba[j] = kmalloc(size, GFP_KERNEL); |
881 | if (!ring->ba[j]) | 881 | if (!ring->ba[j]) |
882 | return -ENOMEM; | 882 | return -ENOMEM; |
883 | mem_allocated += (sizeof(struct buffAdd) * \ | 883 | mem_allocated += size; |
884 | (rxd_count[nic->rxd_mode] + 1)); | ||
885 | while (k != rxd_count[nic->rxd_mode]) { | 884 | while (k != rxd_count[nic->rxd_mode]) { |
886 | ba = &ring->ba[j][k]; | 885 | ba = &ring->ba[j][k]; |
887 | 886 | size = BUF0_LEN + ALIGN_SIZE; | |
888 | ba->ba_0_org = (void *) kmalloc | 887 | ba->ba_0_org = kmalloc(size, GFP_KERNEL); |
889 | (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL); | ||
890 | if (!ba->ba_0_org) | 888 | if (!ba->ba_0_org) |
891 | return -ENOMEM; | 889 | return -ENOMEM; |
892 | mem_allocated += | 890 | mem_allocated += size; |
893 | (BUF0_LEN + ALIGN_SIZE); | ||
894 | tmp = (unsigned long)ba->ba_0_org; | 891 | tmp = (unsigned long)ba->ba_0_org; |
895 | tmp += ALIGN_SIZE; | 892 | tmp += ALIGN_SIZE; |
896 | tmp &= ~((unsigned long) ALIGN_SIZE); | 893 | tmp &= ~((unsigned long) ALIGN_SIZE); |
897 | ba->ba_0 = (void *) tmp; | 894 | ba->ba_0 = (void *) tmp; |
898 | 895 | ||
899 | ba->ba_1_org = (void *) kmalloc | 896 | size = BUF1_LEN + ALIGN_SIZE; |
900 | (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL); | 897 | ba->ba_1_org = kmalloc(size, GFP_KERNEL); |
901 | if (!ba->ba_1_org) | 898 | if (!ba->ba_1_org) |
902 | return -ENOMEM; | 899 | return -ENOMEM; |
903 | mem_allocated | 900 | mem_allocated += size; |
904 | += (BUF1_LEN + ALIGN_SIZE); | ||
905 | tmp = (unsigned long) ba->ba_1_org; | 901 | tmp = (unsigned long) ba->ba_1_org; |
906 | tmp += ALIGN_SIZE; | 902 | tmp += ALIGN_SIZE; |
907 | tmp &= ~((unsigned long) ALIGN_SIZE); | 903 | tmp &= ~((unsigned long) ALIGN_SIZE); |
@@ -3835,23 +3831,22 @@ static int s2io_enable_msi_x(struct s2io_nic *nic) | |||
3835 | u64 rx_mat; | 3831 | u64 rx_mat; |
3836 | u16 msi_control; /* Temp variable */ | 3832 | u16 msi_control; /* Temp variable */ |
3837 | int ret, i, j, msix_indx = 1; | 3833 | int ret, i, j, msix_indx = 1; |
3834 | int size; | ||
3838 | 3835 | ||
3839 | nic->entries = kmalloc(nic->num_entries * sizeof(struct msix_entry), | 3836 | size = nic->num_entries * sizeof(struct msix_entry); |
3840 | GFP_KERNEL); | 3837 | nic->entries = kmalloc(size, GFP_KERNEL); |
3841 | if (!nic->entries) { | 3838 | if (!nic->entries) { |
3842 | DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \ | 3839 | DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \ |
3843 | __func__); | 3840 | __func__); |
3844 | nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++; | 3841 | nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++; |
3845 | return -ENOMEM; | 3842 | return -ENOMEM; |
3846 | } | 3843 | } |
3847 | nic->mac_control.stats_info->sw_stat.mem_allocated | 3844 | nic->mac_control.stats_info->sw_stat.mem_allocated += size; |
3848 | += (nic->num_entries * sizeof(struct msix_entry)); | ||
3849 | 3845 | ||
3850 | memset(nic->entries, 0, nic->num_entries * sizeof(struct msix_entry)); | 3846 | memset(nic->entries, 0, size); |
3851 | 3847 | ||
3852 | nic->s2io_entries = | 3848 | size = nic->num_entries * sizeof(struct s2io_msix_entry); |
3853 | kmalloc(nic->num_entries * sizeof(struct s2io_msix_entry), | 3849 | nic->s2io_entries = kmalloc(size, GFP_KERNEL); |
3854 | GFP_KERNEL); | ||
3855 | if (!nic->s2io_entries) { | 3850 | if (!nic->s2io_entries) { |
3856 | DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", | 3851 | DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", |
3857 | __func__); | 3852 | __func__); |
@@ -3861,10 +3856,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic) | |||
3861 | += (nic->num_entries * sizeof(struct msix_entry)); | 3856 | += (nic->num_entries * sizeof(struct msix_entry)); |
3862 | return -ENOMEM; | 3857 | return -ENOMEM; |
3863 | } | 3858 | } |
3864 | nic->mac_control.stats_info->sw_stat.mem_allocated | 3859 | nic->mac_control.stats_info->sw_stat.mem_allocated += size; |
3865 | += (nic->num_entries * sizeof(struct s2io_msix_entry)); | 3860 | memset(nic->s2io_entries, 0, size); |
3866 | memset(nic->s2io_entries, 0, | ||
3867 | nic->num_entries * sizeof(struct s2io_msix_entry)); | ||
3868 | 3861 | ||
3869 | nic->entries[0].entry = 0; | 3862 | nic->entries[0].entry = 0; |
3870 | nic->s2io_entries[0].entry = 0; | 3863 | nic->s2io_entries[0].entry = 0; |