[v5,18/30] net/ice/base: replace alloc-followed-by-copy with memdup
diff mbox series

Message ID 20190923074448.7847-19-qi.z.zhang@intel.com
State Accepted, archived
Delegated to: xiaolong ye
Headers show
Series
  • net/ice/base: share code update secend batch.
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Zhang, Qi Z Sept. 23, 2019, 7:44 a.m. UTC
ice_memdup() is preferred over an alloc immediately followed by a copy.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Signed-off-by: Paul M Stillwell Jr <paul.m.stillwell.jr@intel.com>
Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/base/ice_flex_pipe.c | 5 ++---
 drivers/net/ice/base/ice_switch.c    | 7 ++-----
 2 files changed, 4 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/ice/base/ice_flex_pipe.c b/drivers/net/ice/base/ice_flex_pipe.c
index 05cd39b17..76c26fd4e 100644
--- a/drivers/net/ice/base/ice_flex_pipe.c
+++ b/drivers/net/ice/base/ice_flex_pipe.c
@@ -4939,12 +4939,11 @@  ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
 		struct ice_vsig_prof *p;
 
 		/* copy to the input list */
-		p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
+		p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
+						       ICE_NONDMA_TO_NONDMA);
 		if (!p)
 			goto err_ice_get_profs_vsig;
 
-		ice_memcpy(p, ent1, sizeof(*p), ICE_NONDMA_TO_NONDMA);
-
 		LIST_ADD_TAIL(&p->list, lst);
 	}
 
diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c
index 64c2aec19..62ccf533c 100644
--- a/drivers/net/ice/base/ice_switch.c
+++ b/drivers/net/ice/base/ice_switch.c
@@ -623,14 +623,11 @@  ice_get_recp_frm_fw(struct ice_hw *hw, struct ice_sw_recipe *recps, u8 rid,
 	recps[rid].big_recp = (num_recps > 1);
 	recps[rid].n_grp_count = num_recps;
 	recps[rid].root_buf = (struct ice_aqc_recipe_data_elem *)
-		ice_calloc(hw, recps[rid].n_grp_count,
-			   sizeof(struct ice_aqc_recipe_data_elem));
+		ice_memdup(hw, tmp, recps[rid].n_grp_count *
+			   sizeof(*recps[rid].root_buf), ICE_NONDMA_TO_NONDMA);
 	if (!recps[rid].root_buf)
 		goto err_unroll;
 
-	ice_memcpy(recps[rid].root_buf, tmp, recps[rid].n_grp_count *
-		   sizeof(*recps[rid].root_buf), ICE_NONDMA_TO_NONDMA);
-
 	/* Copy result indexes */
 	ice_memcpy(recps[rid].res_idxs, result_bm, sizeof(recps[rid].res_idxs),
 		   ICE_NONDMA_TO_NONDMA);