net: ethernet: reduce calls to memset(,0)
Subsystems (12)
cover net: ethernet: reduce calls to memset(,0)
This patch series removes calls to memset(,0) that are redundant when used in conjunction with a zalloc call or by simple zero-assignment of structs.
Robert Eshleman (8):
net/mlx4: use kzalloc instead of kmalloc
net/mlxsw: use pci_zalloc_consistent instead of pci_alloc_consistent
tlan: use pci_zalloc instead of pci_alloc
qed: remove unnecessary memsets
at12: use pci_zalloc instead of pci_alloc
netxen: remove unnecessary memset(,0) calls
net: seeq: replace kmalloc / memset(,0) with kzalloc
net: ethernet: ixp4xx_eth: remove memset(,0) with zalloc
drivers/net/ethernet/atheros/atlx/atl2.c | 5 +- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 - drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 +- .../ethernet/qlogic/netxen/netxen_nic_ctx.c | 36 ++++------ drivers/net/ethernet/qlogic/qed/qed_cxt.c | 4 +- drivers/net/ethernet/qlogic/qed/qed_hw.c | 3 +- drivers/net/ethernet/qlogic/qed/qed_mcp.c | 70 ++++++------------- drivers/net/ethernet/seeq/ether3.c | 3 +- drivers/net/ethernet/ti/tlan.c | 9 ++- drivers/net/ethernet/xscale/ixp4xx_eth.c | 7 +- 11 files changed, 52 insertions(+), 96 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/8 net/mlx4: use kzalloc instead of kmalloc
This patch replaces a kmalloc/memset(,0) call with a call to kzalloc. It also removes a memset(,0) call that always follows a *zalloc call.
--- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 - drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx4/cmd.c +0 -1
@@ -3307,7 +3307,6 @@ int mlx4_get_counter_stats(struct mlx4_dev *dev, int counter_index,if (IS_ERR (mailbox))return PTR_ERR (mailbox); -memset (mailbox->buf,0 ,sizeof (struct mlx4_counter )); if_stat_in_mod = counter_index;if (reset) if_stat_in_mod |=MLX4_QUERY_IF_STAT_RESET ;
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1 -2
@@ -1044,7 +1044,7 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn,struct mlx4_qp_context *context;int err =0 ; - context =kmalloc (sizeof (*context),GFP_KERNEL ); + context =kzalloc (sizeof (*context),GFP_KERNEL );if (!context)return -ENOMEM ;
@@ -1055,7 +1055,6 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, } qp->event = mlx4_en_sqp_event; -memset (context,0 ,sizeof (*context));mlx4_en_fill_qp_context (priv, ring->actual_size, ring->stride,0 ,0 , qpn, ring->cqn,-1 , context); context->db_rec_addr =cpu_to_be64 (ring->wqres.db.dma);
Signature · 1 line
2.20.1
Re: [PATCH 1/8] net/mlx4: use kzalloc instead of kmalloc
Quoted 36 lines · Robert Eshleman
This patch replaces a kmalloc/memset(,0) call with a call to kzalloc. It also removes a
memset(,0)call that always follows a *zalloc call.Signed-off-by Robert Eshleman <[email protected]>--- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 - drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-)drivers/net/ethernet/mellanox/mlx4/cmd.c +0
-1@@ -3307,7 +3307,6 @@ int mlx4_get_counter_stats(struct mlx4_dev *dev, int counter_index,if (IS_ERR (mailbox))return PTR_ERR (mailbox); -memset (mailbox->buf,0 ,sizeof (struct mlx4_counter )); if_stat_in_mod = counter_index;if (reset) if_stat_in_mod |=MLX4_QUERY_IF_STAT_RESET ;drivers/net/ethernet/mellanox/mlx4/en_rx.c +1
-1@@ -1044,7 +1044,7 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn,struct mlx4_qp_context *context;int err =0 ; - context =kmalloc (sizeof (*context),GFP_KERNEL ); + context =kzalloc (sizeof (*context),GFP_KERNEL );if (!context)return -ENOMEM ;
drivers/net/ethernet/mellanox/mlx4/en_rx.c static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, · line 1060
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx4/en_rx.c +0
-1@@ -1055,7 +1055,6 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, } qp->event = mlx4_en_sqp_event; -memset (context,0 ,sizeof (*context));mlx4_en_fill_qp_context (priv, ring->actual_size, ring->stride,0 ,0 , qpn, ring->cqn,-1 , context); context->db_rec_addr =cpu_to_be64 (ring->wqres.db.dma);
Hi,
Thanks for your patch.
It looks good, but misses one similar point you might want to cover:
in drivers/net/ethernet/mellanox/mlx4/port.c:1780 :memset(context, 0, sizeof(*context));
Tariq
PATCH 2/8 net/mlxsw: use pci_zalloc_consistent instead of pci_alloc_consistent
In reply to Robert EshlemanThis patch replaces a call to pci_alloc_consistent and then memset(0,) with a single call to pci_zalloc_consistent.
--- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/pci.c +3 -4
@@ -830,12 +830,11 @@ static int mlxsw_pci_queue_init(struct mlxsw_pci *mlxsw_pci, char *mbox,tasklet_init (&q->tasklet, q_ops->tasklet, (unsigned long ) q); mem_item->size =MLXSW_PCI_AQ_SIZE ; - mem_item->buf =pci_alloc_consistent (mlxsw_pci->pdev, - mem_item->size, - &mem_item->mapaddr); + mem_item->buf =pci_zalloc_consistent (mlxsw_pci->pdev, + mem_item->size, + &mem_item->mapaddr);if (!mem_item->buf)return -ENOMEM ; -memset (mem_item->buf,0 , mem_item->size); q->elem_info =kcalloc (q->count,sizeof (*q->elem_info),GFP_KERNEL );if (!q->elem_info) {
Signature · 1 line
2.20.1
PATCH 3/8 tlan: use pci_zalloc instead of pci_alloc
In reply to Robert EshlemanThis patch replaces a pci_alloc_consistent and memset(,0) call with a single call to pci_zalloc_consistent.
--- drivers/net/ethernet/ti/tlan.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/tlan.c +4 -5
@@ -845,17 +845,16 @@ static int tlan_init(struct net_device *dev) dma_size = (TLAN_NUM_RX_LISTS +TLAN_NUM_TX_LISTS ) * (sizeof (struct tlan_list )); - priv->dma_storage =pci_alloc_consistent (priv->pci_dev, - dma_size, - &priv->dma_storage_dma); + priv->dma_storage =pci_zalloc_consistent (priv->pci_dev, + dma_size, + &priv->dma_storage_dma); priv->dma_size = dma_size; -if (priv->dma_storage ==NULL ) { +if (!priv->dma_storage) {pr_err ("Could not allocate lists and buffers for %s\n" , dev->name);return -ENOMEM ; } -memset (priv->dma_storage,0 , dma_size); priv->rx_list = (struct tlan_list *)ALIGN ((unsigned long )priv->dma_storage,8 ); priv->rx_list_dma =ALIGN (priv->dma_storage_dma,8 );
Signature · 1 line
2.20.1
Re: [PATCH 3/8] tlan: use pci_zalloc instead of pci_alloc
Quoted 2 lines · Robert Eshleman
This patch replaces a
pci_alloc_consistentandmemset(,0)call with a single call topci_zalloc_consistent.
[]
drivers/net/ethernet/ti/tlan.c
Quoted 1 line
drivers/net/ethernet/ti/tlan.c +0
-0
[]
Quoted 6 lines
drivers/net/ethernet/ti/tlan.c +0
-2@@ -845,17 +845,16 @@ static int tlan_init(struct net_device *dev) dma_size = (TLAN_NUM_RX_LISTS +TLAN_NUM_TX_LISTS ) * (sizeof (struct tlan_list )); - priv->dma_storage = pci_alloc_consistent(priv->pci_dev, - dma_size,
drivers/net/ethernet/ti/tlan.c static int tlan_init(struct net_device *dev) · line 855
Quoted 10 lines
drivers/net/ethernet/ti/tlan.c +4
-2- &priv->dma_storage_dma); + priv->dma_storage =pci_zalloc_consistent (priv->pci_dev, + dma_size, + &priv->dma_storage_dma); priv->dma_size = dma_size; -if (priv->dma_storage ==NULL ) { +if (!priv->dma_storage) {pr_err ("Could not allocate lists and buffers for %s\n" , dev->name);
unrelated trivia:
This pr_err (and likely others in this file)
could be replace by netdev_err
Re: [PATCH 3/8] tlan: use pci_zalloc instead of pci_alloc
Quoted 25 lines · Joe Perches
Quoted 2 lines · Robert Eshleman
This patch replaces a
pci_alloc_consistentandmemset(,0)call with a single call topci_zalloc_consistent.[]
drivers/net/ethernet/ti/tlan.c
Quoted 1 line
drivers/net/ethernet/ti/tlan.c +0
-0[]
Quoted 6 lines
drivers/net/ethernet/ti/tlan.c +0
-2@@ -845,17 +845,16 @@ static int tlan_init(struct net_device *dev) dma_size = (TLAN_NUM_RX_LISTS +TLAN_NUM_TX_LISTS ) * (sizeof (struct tlan_list )); - priv->dma_storage = pci_alloc_consistent(priv->pci_dev, - dma_size,drivers/net/ethernet/ti/tlan.c static int tlan_init(struct net_device *dev) · line 855
Quoted 10 lines
drivers/net/ethernet/ti/tlan.c +4
-2- &priv->dma_storage_dma); + priv->dma_storage =pci_zalloc_consistent (priv->pci_dev, + dma_size, + &priv->dma_storage_dma); priv->dma_size = dma_size; -if (priv->dma_storage ==NULL ) { +if (!priv->dma_storage) {pr_err ("Could not allocate lists and buffers for %s\n" , dev->name);unrelated trivia:
Quoted 3 lines
This
pr_err(and likely others in this file)
could be replace bynetdev_err
Definitely good to know (I may make that change too). Thanks Joe.
-Bobby
PATCH 4/8 qed: remove unnecessary memsets
In reply to Robert EshlemanThis patch replaces unnecessary memset(,0) calls with simply assigning structs to zero.
--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 4 +- drivers/net/ethernet/qlogic/qed/qed_hw.c | 3 +- drivers/net/ethernet/qlogic/qed/qed_mcp.c | 70 ++++++++--------------- 3 files changed, 25 insertions(+), 52 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_cxt.c +1 -3
@@ -902,12 +902,10 @@ static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn)struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;u32 conn_num, total_size, ent_per_page, psz, i;struct qed_ilt_client_cfg *p_src; -struct qed_src_iids src_iids; +struct qed_src_iids src_iids = {0 };struct qed_dma_mem *p_t2;int rc; -memset (&src_iids,0 ,sizeof (src_iids)); -/* if the SRC ILT client is inactive - there are no connection * requiring the searcer, leave. */
drivers/net/ethernet/qlogic/qed/qed_hw.c +1 -2
@@ -831,7 +831,7 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, const char *phase) { u32 size = PAGE_SIZE / 2, val; -struct qed_dmae_params params; +struct qed_dmae_params params = {0 };int rc =0 ;dma_addr_t p_phys;void *p_virt;
@@ -864,7 +864,6 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, (u64 )p_phys, p_virt, (u64)(p_phys + size), (u8 *)p_virt + size, size); -memset (¶ms,0 ,sizeof (params)); rc =qed_dmae_host2host (p_hwfn, p_ptt, p_phys, p_phys + size, size /4 /* size_in_dwords */ , ¶ms);if (rc) {
drivers/net/ethernet/qlogic/qed/qed_mcp.c +23 -47
251 lines not on this page · raw message
Signature · 1 line
2.20.1
RE: [PATCH 4/8] qed: remove unnecessary memsets
Quoted 343 lines
From: Robert Eshleman <[email protected]>
Sent: Wednesday, February 27, 2019 8:10 AMThis patch replaces unnecessary
memset(,0)calls with simply assigning structs to zero.Signed-off-by Robert Eshleman <[email protected]>--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 4 +- drivers/net/ethernet/qlogic/qed/qed_hw.c | 3 +- drivers/net/ethernet/qlogic/qed/qed_mcp.c | 70 ++++++++--------------- 3 files changed, 25 insertions(+), 52 deletions(-)drivers/net/ethernet/qlogic/qed/qed_cxt.c +1
-3@@ -902,12 +902,10 @@ static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn)struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;u32 conn_num, total_size, ent_per_page, psz, i;struct qed_ilt_client_cfg *p_src; -struct qed_src_iids src_iids; +struct qed_src_iids src_iids = {0 };struct qed_dma_mem *p_t2;int rc; -memset (&src_iids,0 ,sizeof (src_iids)); -/* if the SRC ILT client is inactive - there are no connection * requiring the searcer, leave. drivers/net/ethernet/qlogic/qed/qed_cxt.c +0
-0*/ drivers/net/ethernet/qlogic/qed/qed_hw.c +1
-2@@ -831,7 +831,7 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, const char *phase) { u32 size = PAGE_SIZE / 2, val; -struct qed_dmae_params params; +struct qed_dmae_params params = {0 };int rc =0 ;dma_addr_t p_phys;void *p_virt;@@ -864,7 +864,6 @@ int qed_dmae_sanity(struct qed_hwfn *p_hwfn, (u64 )p_phys, p_virt, (u64)(p_phys + size), (u8 *)p_virt + size, size); -memset (¶ms,0 ,sizeof (params)); rc =qed_dmae_host2host (p_hwfn, p_ptt, p_phys, p_phys + size, size /4 /* size_in_dwords */ , ¶ms);if (rc) {drivers/net/ethernet/qlogic/qed/qed_mcp.c +5
-9@@ -642,10 +642,9 @@ int qed_mcp_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param) { -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };int rc; -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd = cmd; mb_params.param = param;@@ -667,10 +666,9 @@ qed_mcp_nvm_wr_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param, u32 i_txn_size, u32 *i_buf) { -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };int rc; -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd = cmd; mb_params.param = param; mb_params.p_data_src = i_buf;@@ -695,11 +693,10 @@ int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn, u32 *o_mcp_resp, u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf) { -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };u8 raw_data[MCP_DRV_NVM_BUF_LEN ];int rc; -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd = cmd; mb_params.param = param; mb_params.p_data_dst = raw_data;@@ -821,13 +818,12 @@ __qed_mcp_load_req(struct qed_hwfn *p_hwfn,struct qed_load_req_in_params *p_in_params, struct qed_load_req_out_params *p_out_params) { - struct qed_mcp_mb_params mb_params; -struct load_req_stc load_req; + struct qed_mcp_mb_params mb_params = {0}; +struct load_req_stc load_req = {0 };struct load_rsp_stc load_rsp;u32 hsi_ver;int rc; -memset (&load_req,0 ,sizeof (load_req)); load_req.drv_ver_0 = p_in_params->drv_ver_0; load_req.drv_ver_1 = p_in_params->drv_ver_1; load_req.fw_ver = p_in_params->fw_ver; @@ -843,7 +839,6 @@ __qed_mcp_load_req(struct qed_hwfn *p_hwfn,drivers/net/ethernet/qlogic/qed/qed_mcp.c +0
-1DRV_ID_MCP_HSI_VER_CURRENT : (p_in_params->hsi_ver <<DRV_ID_MCP_HSI_VER_SHIFT ); -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_LOAD_REQ ; mb_params.param = PDA_COMP | hsi_ver | p_hwfn->cdev-Quoted 1 line
drv_type;drivers/net/ethernet/qlogic/qed/qed_mcp.c +2
-3mb_params.p_data_src = &load_req;@@ -959,12 +954,11 @@ int qed_mcp_load_req(struct qed_hwfn *p_hwfn,struct qed_ptt *p_ptt, struct qed_load_req_params *p_params) { - struct qed_load_req_out_params out_params; -struct qed_load_req_in_params in_params; + struct qed_load_req_out_params out_params = {0}; +struct qed_load_req_in_params in_params = {0 };u8 mfw_drv_role, mfw_force_cmd;int rc; -memset (&in_params,0 ,sizeof (in_params)); in_params.hsi_ver =QED_LOAD_REQ_HSI_VER_DEFAULT ; in_params.drv_ver_0 =QED_VERSION ; in_params.drv_ver_1 = qed_get_config_bitmap(); @@ -981,7 +975,6 @@ int qed_mcp_load_req(struct qed_hwfn *p_hwfn,drivers/net/ethernet/qlogic/qed/qed_mcp.c +0
-1in_params.force_cmd = mfw_force_cmd; in_params.avoid_eng_reset = p_params->avoid_eng_reset; -memset (&out_params,0 ,sizeof (out_params)); rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params,
&out_params);drivers/net/ethernet/qlogic/qed/qed_mcp.c +1
-2if (rc)return rc;@@ -1072,7 +1065,7 @@ int qed_mcp_load_req(struct qed_hwfn *p_hwfn,int qed_mcp_unload_req (struct qed_hwfn *p_hwfn,struct qed_ptt *p_ptt) { -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };u32 wol_param;switch (p_hwfn->cdev->wol_config) {@@ -1091,7 +1084,6 @@ int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) wol_param =DRV_MB_PARAM_UNLOAD_WOL_MCP ; } -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_UNLOAD_REQ ; mb_params.param = wol_param;mb_params.flags =
QED_MB_FLAG_CAN_SLEEP|QED_MB_FLAG_AVOID_BLOCK; @@ -1101,17 +1093,15 @@ intqed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)int qed_mcp_unload_done(struct
qed_hwfn*p_hwfn, structqed_ptt*p_ptt) {drivers/net/ethernet/qlogic/qed/qed_mcp.c +3
-6-struct qed_mcp_mb_params mb_params; -struct mcp_mac wol_mac; +struct qed_mcp_mb_params mb_params = {0 }; +struct mcp_mac wol_mac = {0 }; -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_UNLOAD_DONE ;/* Set the primary MAC if WoL is enabled */ if (p_hwfn->cdev->wol_config ==QED_OV_WOL_ENABLED ) {u8 *p_mac = p_hwfn->cdev->wol_mac; -memset (&wol_mac,0 ,sizeof (wol_mac)); wol_mac.mac_upper = p_mac[0 ] <<8 | p_mac[1 ]; wol_mac.mac_lower = p_mac[2 ] <<24 | p_mac[3 ] <<16 | p_mac[4 ] <<8 | p_mac[5 ];@@ -1167,7 +1157,7 @@ int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn, u32 mfw_func_offsize = qed_rd(p_hwfn, p_ptt, addr);u32 func_addr =SECTION_ADDR (mfw_func_offsize,MCP_PF_ID (p_hwfn)); -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };int rc;int i;@@ -1176,7 +1166,6 @@ int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,"Acking VFs [%08x,...,%08x] - %08x\n" , i * 32, (i + 1) * 32 - 1, vfs_to_ack[i]); -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_VF_DISABLED_DONE ; mb_params.p_data_src = vfs_to_ack;mb_params.data_src_size =
VF_MAX_STATIC/ 8; @@ -1455,13
+1444,12 @@ static void qed_mcp_handle_link_change(structqed_hwfn*p_hwfn, intqed_mcp_set_link(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, bool b_up){
structqed_mcp_link_params*params = &p_hwfn->mcp_info-Quoted 1 line
link_input;drivers/net/ethernet/qlogic/qed/qed_mcp.c +2
-3-struct qed_mcp_mb_params mb_params; -struct eth_phy_cfg phy_cfg; +struct qed_mcp_mb_params mb_params = {0 }; +struct eth_phy_cfg phy_cfg = {0 };int rc =0 ;u32 cmd;/* Set the shmem configuration according to params */ -memset (&phy_cfg,0 ,sizeof (phy_cfg)); cmd = b_up ? DRV_MSG_CODE_INIT_PHY :
DRV_MSG_CODE_LINK_RESET;drivers/net/ethernet/qlogic/qed/qed_mcp.c +1
-0if (!params->speed.autoneg) phy_cfg.speed = params->speed.forced_speed; @@ -1505,7 +1493,6 @@ int qed_mcp_set_link(struct qed_hwfn *p_hwfn, struct
qed_ptt*p_ptt, boolb_up)drivers/net/ethernet/qlogic/qed/qed_mcp.c +0
-1"Resetting link\n"); } -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd = cmd; mb_params.p_data_src = &phy_cfg; mb_params.data_src_size = sizeof(phy_cfg); @@ -1534,7 +1521,7@@ static void qed_mcp_send_protocol_stats(struct
qed_hwfn*p_hwfn, {drivers/net/ethernet/qlogic/qed/qed_mcp.c +1
-2enum qed_mcp_protocol_type stats_type;union qed_mcp_protocol_stats stats; -struct qed_mcp_mb_params mb_params; +struct qed_mcp_mb_params mb_params = {0 };u32 hsi_param;switch (type) {@@ -1561,7 +1548,6 @@ static void qed_mcp_send_protocol_stats(struct qed_hwfn *p_hwfn,qed_get_protocol_stats (p_hwfn->cdev, stats_type, &stats); -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_GET_STATS ; mb_params.param = hsi_param;drivers/net/ethernet/qlogic/qed/qed_mcp.c +2
-4mb_params.p_data_src = &stats;@@ -2370,20 +2356,18 @@ qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, struct qed_mcp_drv_version *p_ver) { -struct qed_mcp_mb_params mb_params; -struct drv_version_stc drv_version; +struct qed_mcp_mb_params mb_params = {0 }; +struct drv_version_stc drv_version = {0 };__be32 val;u32 i;int rc; -memset (&drv_version,0 ,sizeof (drv_version)); drv_version.version = p_ver->version;for (i =0 ; i < (MCP_DRV_VER_STR_SIZE -4 ) /sizeof (u32); i++) { val =cpu_to_be32 (*((u32 *)&p_ver->name[i *sizeof (u32)])); *(__be32 *)&drv_version.name[i *sizeof (u32)] = val; } -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_SET_VERSION ;drivers/net/ethernet/qlogic/qed/qed_mcp.c +1
-0mb_params.p_data_src = &drv_version; mb_params.data_src_size = sizeof(drv_version); @@ -2536,11 +2520,10 @@ int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn, intqed_mcp_ov_update_mac(struct
qed_hwfn*p_hwfn,drivers/net/ethernet/qlogic/qed/qed_mcp.c +3
-6struct qed_ptt *p_ptt, u8 *mac) { - struct qed_mcp_mb_params mb_params; + struct qed_mcp_mb_params mb_params = {0};u32 mfw_mac[2 ];int rc; -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd =DRV_MSG_CODE_SET_VMAC ; mb_params.param =DRV_MSG_CODE_VMAC_TYPE_MAC <<DRV_MSG_CODE_VMAC_TYPE_SHIFT ;@@ -3197,12 +3180,10 @@ qed_mcp_resc_allocation_msg(struct qed_hwfn *p_hwfn, struct qed_resc_alloc_in_params *p_in_params, struct qed_resc_alloc_out_params *p_out_params) { -struct qed_mcp_mb_params mb_params; -struct resource_info mfw_resc_info; +struct qed_mcp_mb_params mb_params = {0 }; +struct resource_info mfw_resc_info = {0 };int rc; -memset (&mfw_resc_info,0 ,sizeof (mfw_resc_info)); - mfw_resc_info.res_id =qed_mcp_get_mfw_res_id (p_in_params- >res_id);drivers/net/ethernet/qlogic/qed/qed_mcp.c +0
-1if (mfw_resc_info.res_id ==RESOURCE_NUM_INVALID ) { DP_ERR(p_hwfn,@@ -3224,7 +3205,6 @@ qed_mcp_resc_allocation_msg(struct qed_hwfn *p_hwfn, return -EINVAL ; } -memset (&mb_params,0 ,sizeof (mb_params)); mb_params.cmd = p_in_params->cmd; mb_params.param =QED_RESC_ALLOC_VERSION ;mb_params.p_data_src =
&mfw_resc_info; @@ -3277,15 +3257,13
@@ qed_mcp_set_resc_max_val(structqed_hwfn*p_hwfn,drivers/net/ethernet/qlogic/qed/qed_mcp.c +4
-8enum qed_resources res_id, u32 resc_max_val, u32 *p_mcp_resp) { - struct qed_resc_alloc_out_params out_params; -struct qed_resc_alloc_in_params in_params; + struct qed_resc_alloc_out_params out_params = {0}; +struct qed_resc_alloc_in_params in_params = {0 };int rc; -memset (&in_params,0 ,sizeof (in_params)); in_params.cmd =DRV_MSG_SET_RESOURCE_VALUE_MSG ; in_params.res_id = res_id; in_params.resc_max_val = resc_max_val; -memset (&out_params,0 ,sizeof (out_params)); rc =qed_mcp_resc_allocation_msg (p_hwfn, p_ptt, &in_params, &out_params);if (rc)@@ -3302,14 +3280,12 @@ qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn, enum qed_resources res_id, u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start) { -struct qed_resc_alloc_out_params out_params; -struct qed_resc_alloc_in_params in_params; +struct qed_resc_alloc_out_params out_params = {0 }; +struct qed_resc_alloc_in_params in_params = {0 };int rc; -memset (&in_params,0 ,sizeof (in_params)); in_params.cmd =DRV_MSG_GET_RESOURCE_ALLOC_MSG ; in_params.res_id = res_id; -memset (&out_params,0 ,sizeof (out_params)); rc =qed_mcp_resc_allocation_msg (p_hwfn, p_ptt, &in_params, &out_params);
Quoted 3 lines
if (rc)
--
2.20.1
Thanks,
PATCH 5/8 at12: use pci_zalloc instead of pci_alloc
In reply to Robert EshlemanThis patch replaces a pci_alloc and memset(,0) call with a single call to pci_zalloc.
--- drivers/net/ethernet/atheros/atlx/atl2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/atheros/atlx/atl2.c +2 -3
@@ -300,11 +300,10 @@ static s32 atl2_setup_ring_resources(struct atl2_adapter *adapter) adapter->txs_ring_size *4 +7 +/* dword align */ adapter->rxd_ring_size *1536 +127 ;/* 128bytes align */ - adapter->ring_vir_addr =pci_alloc_consistent (pdev, size, - &adapter->ring_dma); + adapter->ring_vir_addr =pci_zalloc_consistent (pdev, size, + &adapter->ring_dma);if (!adapter->ring_vir_addr)return -ENOMEM ; -memset (adapter->ring_vir_addr,0 , adapter->ring_size);/* Init TXD Ring */ adapter->txd_dma = adapter->ring_dma ;
Signature · 1 line
2.20.1
Re: [PATCH 5/8] at12: use pci_zalloc instead of pci_alloc
Quoted 2 lines · Robert Eshleman
This patch replaces a
pci_allocandmemset(,0)call with a single call topci_zalloc.
Please don't move from one deprecated API to another one. If you feel like cleaning up DMA API calls please move to dma_alloc_coherent, and do that for the whole DMA API usage.
PATCH 6/8 netxen: remove unnecessary memset(,0) calls
In reply to Robert EshlemanThis patch reduces calls to memset(,0) by replacing memset(,0) calls that only zero-out newly declared structs with simply assigning those structs to zero structs.
It also removes a pci_alloc_consistent call followed by a memset(,0) call by simply using pci_zalloc_consistent.
--- .../ethernet/qlogic/netxen/netxen_nic_ctx.c | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-)
drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c +13 -23
@@ -99,8 +99,7 @@ netxen_issue_cmd(struct netxen_adapter *adapter, struct netxen_cmd_args *cmd)static int netxen_get_minidump_template_size (struct netxen_adapter *adapter) { -struct netxen_cmd_args cmd; -memset (&cmd,0 ,sizeof (cmd)); +struct netxen_cmd_args cmd = {0 }; cmd.req.cmd =NX_CDRP_CMD_TEMP_SIZE ;memset (&cmd.rsp,1 ,sizeof (struct _cdrp_cmd ));netxen_issue_cmd (adapter, &cmd);
@@ -120,7 +119,7 @@ netxen_get_minidump_template(struct netxen_adapter *adapter)dma_addr_t md_template_addr;void *addr;u32 size; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; size = adapter->mdump.md_template_size;if (size ==0 ) {
@@ -135,7 +134,6 @@ netxen_get_minidump_template(struct netxen_adapter *adapter)return -ENOMEM ; } -memset (&cmd,0 ,sizeof (cmd));memset (&cmd.rsp,1 ,sizeof (struct _cdrp_cmd )); cmd.req.cmd =NX_CDRP_CMD_GET_TEMP_HDR ; cmd.req.arg1 =LSD (md_template_addr);
@@ -233,9 +231,8 @@ nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu) {u32 rcode =NX_RCODE_SUCCESS ;struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.cmd =NX_CDRP_CMD_SET_MTU ; cmd.req.arg1 = recv_ctx->context_id; cmd.req.arg2 = mtu;
@@ -254,9 +251,8 @@ int nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter, u32 speed, u32 duplex, u32 autoneg) { - struct netxen_cmd_args cmd; + struct netxen_cmd_args cmd = {0}; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.cmd =NX_CDRP_CMD_CONFIG_GBE_PORT ; cmd.req.arg1 = speed; cmd.req.arg2 = duplex;
@@ -276,7 +272,7 @@ nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter)nx_cardrsp_sds_ring_t *prsp_sds;struct nx_host_rds_ring *rds_ring;struct nx_host_sds_ring *sds_ring; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 };dma_addr_t hostrq_phys_addr, cardrsp_phys_addr;u64 phys_addr;
@@ -359,7 +355,6 @@ nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter) } phys_addr = hostrq_phys_addr; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.arg1 = (u32)(phys_addr >>32 ); cmd.req.arg2 = (u32)(phys_addr &0xffffffff ); cmd.req.arg3 = rq_size;
@@ -413,9 +408,8 @@ static void nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter) {struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.arg1 = recv_ctx->context_id; cmd.req.arg2 =NX_DESTROY_CTX_RESET ; cmd.req.arg3 =0 ;
@@ -520,9 +514,8 @@ nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter)static void nx_fw_cmd_destroy_tx_ctx (struct netxen_adapter *adapter) { -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.arg1 = adapter->tx_context_id; cmd.req.arg2 =NX_DESTROY_CTX_RESET ; cmd.req.arg3 =0 ;
@@ -538,9 +531,8 @@ int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val) { u32 rcode; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.arg1 = reg; cmd.req.arg2 =0 ; cmd.req.arg3 =0 ;
@@ -561,9 +553,8 @@ int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val) { u32 rcode; -struct netxen_cmd_args cmd; +struct netxen_cmd_args cmd = {0 }; -memset (&cmd,0 ,sizeof (cmd)); cmd.req.arg1 = reg; cmd.req.arg2 = val; cmd.req.arg3 =0 ;
@@ -763,15 +754,14 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter) recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; - addr =pci_alloc_consistent (pdev, -sizeof (struct netxen_ring_ctx ) +sizeof (uint32_t ), - &recv_ctx->phys_addr); -if (addr ==NULL ) { + addr =pci_zalloc_consistent (pdev, +sizeof (struct netxen_ring_ctx ) +sizeof (uint32_t ), + &recv_ctx->phys_addr); +if (!addr) {dev_err (&pdev->dev,"failed to allocate hw context\n" );return -ENOMEM ; } -memset (addr,0 ,sizeof (struct netxen_ring_ctx )); recv_ctx->hwctx = addr; recv_ctx->hwctx->ctx_id =cpu_to_le32 (port); recv_ctx->hwctx->cmd_consumer_offset =
Signature · 1 line
2.20.1
PATCH 7/8 net: seeq: replace kmalloc / memset(,0) with kzalloc
In reply to Robert EshlemanThis patch reduces a call to memset(,0) by replacing a kmalloc call with a kzalloc call.
--- drivers/net/ethernet/seeq/ether3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/seeq/ether3.c +1 -2
@@ -223,7 +223,7 @@ ether3_addr(char *addr, struct expansion_card *ec)static int ether3_ramtest (struct net_device *dev,unsigned char byte) { -unsigned char *buffer =kmalloc (RX_END ,GFP_KERNEL ); +unsigned char *buffer =kzalloc (RX_END ,GFP_KERNEL );int i,ret =0 ;int max_errors =4 ;int bad =-1 ;
@@ -231,7 +231,6 @@ ether3_ramtest(struct net_device *dev, unsigned char byte)if (!buffer)return 1 ; -memset (buffer, byte,RX_END );ether3_setbuffer (dev, buffer_write,0 );ether3_writebuffer (dev, buffer,TX_END );ether3_setbuffer (dev, buffer_write,RX_START );
Signature · 1 line
2.20.1
Re: [PATCH 7/8] net: seeq: replace kmalloc / memset(,0) with kzalloc
Quoted 22 lines · Robert Eshleman
This patch reduces a call to
memset(,0)by replacing a kmalloc call with a kzalloc call.Signed-off-by Robert Eshleman <[email protected]>--- drivers/net/ethernet/seeq/ether3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/ethernet/seeq/ether3.c +1
-1@@ -223,7 +223,7 @@ ether3_addr(char *addr, struct expansion_card *ec)static int ether3_ramtest (struct net_device *dev,unsigned char byte) { -unsigned char *buffer =kmalloc (RX_END ,GFP_KERNEL ); +unsigned char *buffer =kzalloc (RX_END ,GFP_KERNEL );int i,ret =0 ;int max_errors =4 ;int bad =-1 ;
drivers/net/ethernet/seeq/ether3.c ether3_ramtest(struct net_device *dev, unsigned char byte) · line 234
Quoted 4 lines
drivers/net/ethernet/seeq/ether3.c +0
-1@@ -231,7 +231,6 @@ ether3_ramtest(struct net_device *dev, unsigned char byte)if (!buffer)return 1 ; -memset (buffer, byte,RX_END );
Byte is not zero, so the intent of this patch does not apply here. Dropping this from the patch set in v2.
Quoted 6 lines
drivers/net/ethernet/seeq/ether3.c +0
-0ether3_setbuffer (dev, buffer_write,0 );ether3_writebuffer (dev, buffer,TX_END );ether3_setbuffer (dev, buffer_write,RX_START );Signature · 1 line
2.20.1
PATCH 8/8 net: ethernet: ixp4xx_eth: remove memset(,0) with zalloc
In reply to Robert EshlemanThis patch removes a call to memset(,0) by replacing the prior call to dma_pool_alloc with a call to dma_pool_zalloc.
--- drivers/net/ethernet/xscale/ixp4xx_eth.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/xscale/ixp4xx_eth.c +3 -4
@@ -1107,11 +1107,10 @@ static int init_queues(struct port *port)if (!dma_pool)return -ENOMEM ; } - -if (!(port->desc_tab =dma_pool_alloc (dma_pool,GFP_KERNEL , - &port->desc_tab_phys))) + port->desc_tab =dma_pool_zalloc (dma_pool,GFP_KERNEL , + &port->desc_tab_phys); +if (!port->desc_tab)return -ENOMEM ; -memset (port->desc_tab,0 ,POOL_ALLOC_SIZE );memset (port->rx_buff_tab,0 ,sizeof (port->rx_buff_tab));/* tables */ memset (port->tx_buff_tab,0 ,sizeof (port->tx_buff_tab));
Signature · 1 line
2.20.1
Quoted 3 lines · Robert Eshleman
This patch series removes calls to
memset(,0)that are redundant when used in conjunction with a zalloc call or by simple zero-assignment of structs.
NAK. pci_zalloc_consistent is just as deprecated as pci_alloc_consistent, and if you look at the implementation you'll see that we actual zero the memory for both of them.
If you want to do some DMA-related busy work please just bulk convert drivers from the PCI DMA API to the proper generic DMA API. Bonus points for automatіng that using a cocchinelle script.