@@ -31,7 +31,7 @@ static const struct ice_tunnel_type_scan tnls[] = {
3131 * Verifies various attributes of the package file, including length, format
3232 * version, and the requirement of at least one segment.
3333 */
34- static enum ice_ddp_state ice_verify_pkg (struct ice_pkg_hdr * pkg , u32 len )
34+ static enum ice_ddp_state ice_verify_pkg (const struct ice_pkg_hdr * pkg , u32 len )
3535{
3636 u32 seg_count ;
3737 u32 i ;
@@ -57,13 +57,13 @@ static enum ice_ddp_state ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
5757 /* all segments must fit within length */
5858 for (i = 0 ; i < seg_count ; i ++ ) {
5959 u32 off = le32_to_cpu (pkg -> seg_offset [i ]);
60- struct ice_generic_seg_hdr * seg ;
60+ const struct ice_generic_seg_hdr * seg ;
6161
6262 /* segment header must fit */
6363 if (len < off + sizeof (* seg ))
6464 return ICE_DDP_PKG_INVALID_FILE ;
6565
66- seg = (struct ice_generic_seg_hdr * )(( u8 * ) pkg + off ) ;
66+ seg = (void * ) pkg + off ;
6767
6868 /* segment body must fit */
6969 if (len < off + le32_to_cpu (seg -> seg_size ))
@@ -119,13 +119,13 @@ static enum ice_ddp_state ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
119119 *
120120 * This helper function validates a buffer's header.
121121 */
122- static struct ice_buf_hdr * ice_pkg_val_buf (struct ice_buf * buf )
122+ static const struct ice_buf_hdr * ice_pkg_val_buf (const struct ice_buf * buf )
123123{
124- struct ice_buf_hdr * hdr ;
124+ const struct ice_buf_hdr * hdr ;
125125 u16 section_count ;
126126 u16 data_end ;
127127
128- hdr = (struct ice_buf_hdr * )buf -> buf ;
128+ hdr = (const struct ice_buf_hdr * )buf -> buf ;
129129 /* verify data */
130130 section_count = le16_to_cpu (hdr -> section_count );
131131 if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT )
@@ -165,8 +165,8 @@ static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
165165 * unexpected value has been detected (for example an invalid section count or
166166 * an invalid buffer end value).
167167 */
168- static struct ice_buf_hdr * ice_pkg_enum_buf (struct ice_seg * ice_seg ,
169- struct ice_pkg_enum * state )
168+ static const struct ice_buf_hdr * ice_pkg_enum_buf (struct ice_seg * ice_seg ,
169+ struct ice_pkg_enum * state )
170170{
171171 if (ice_seg ) {
172172 state -> buf_table = ice_find_buf_table (ice_seg );
@@ -1800,9 +1800,9 @@ int ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
18001800 * success it returns a pointer to the segment header, otherwise it will
18011801 * return NULL.
18021802 */
1803- static struct ice_generic_seg_hdr *
1803+ static const struct ice_generic_seg_hdr *
18041804ice_find_seg_in_pkg (struct ice_hw * hw , u32 seg_type ,
1805- struct ice_pkg_hdr * pkg_hdr )
1805+ const struct ice_pkg_hdr * pkg_hdr )
18061806{
18071807 u32 i ;
18081808
@@ -1813,11 +1813,9 @@ ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
18131813
18141814 /* Search all package segments for the requested segment type */
18151815 for (i = 0 ; i < le32_to_cpu (pkg_hdr -> seg_count ); i ++ ) {
1816- struct ice_generic_seg_hdr * seg ;
1816+ const struct ice_generic_seg_hdr * seg ;
18171817
1818- seg = (struct ice_generic_seg_hdr
1819- * )((u8 * )pkg_hdr +
1820- le32_to_cpu (pkg_hdr -> seg_offset [i ]));
1818+ seg = (void * )pkg_hdr + le32_to_cpu (pkg_hdr -> seg_offset [i ]);
18211819
18221820 if (le32_to_cpu (seg -> seg_type ) == seg_type )
18231821 return seg ;
@@ -2354,12 +2352,12 @@ ice_get_set_tx_topo(struct ice_hw *hw, u8 *buf, u16 buf_size,
23542352 *
23552353 * Return: zero when update was successful, negative values otherwise.
23562354 */
2357- int ice_cfg_tx_topo (struct ice_hw * hw , u8 * buf , u32 len )
2355+ int ice_cfg_tx_topo (struct ice_hw * hw , const void * buf , u32 len )
23582356{
2359- u8 * current_topo , * new_topo = NULL ;
2360- struct ice_run_time_cfg_seg * seg ;
2361- struct ice_buf_hdr * section ;
2362- struct ice_pkg_hdr * pkg_hdr ;
2357+ u8 * new_topo = NULL , * topo __free ( kfree ) = NULL ;
2358+ const struct ice_run_time_cfg_seg * seg ;
2359+ const struct ice_buf_hdr * section ;
2360+ const struct ice_pkg_hdr * pkg_hdr ;
23632361 enum ice_ddp_state state ;
23642362 u16 offset , size = 0 ;
23652363 u32 reg = 0 ;
@@ -2375,15 +2373,13 @@ int ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len)
23752373 return - EOPNOTSUPP ;
23762374 }
23772375
2378- current_topo = kzalloc (ICE_AQ_MAX_BUF_LEN , GFP_KERNEL );
2379- if (!current_topo )
2376+ topo = kzalloc (ICE_AQ_MAX_BUF_LEN , GFP_KERNEL );
2377+ if (!topo )
23802378 return - ENOMEM ;
23812379
2382- /* Get the current Tx topology */
2383- status = ice_get_set_tx_topo (hw , current_topo , ICE_AQ_MAX_BUF_LEN , NULL ,
2384- & flags , false);
2385-
2386- kfree (current_topo );
2380+ /* Get the current Tx topology flags */
2381+ status = ice_get_set_tx_topo (hw , topo , ICE_AQ_MAX_BUF_LEN , NULL , & flags ,
2382+ false);
23872383
23882384 if (status ) {
23892385 ice_debug (hw , ICE_DBG_INIT , "Get current topology is failed\n" );
@@ -2419,7 +2415,7 @@ int ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len)
24192415 goto update_topo ;
24202416 }
24212417
2422- pkg_hdr = (struct ice_pkg_hdr * )buf ;
2418+ pkg_hdr = (const struct ice_pkg_hdr * )buf ;
24232419 state = ice_verify_pkg (pkg_hdr , len );
24242420 if (state ) {
24252421 ice_debug (hw , ICE_DBG_INIT , "Failed to verify pkg (err: %d)\n" ,
@@ -2428,7 +2424,7 @@ int ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len)
24282424 }
24292425
24302426 /* Find runtime configuration segment */
2431- seg = (struct ice_run_time_cfg_seg * )
2427+ seg = (const struct ice_run_time_cfg_seg * )
24322428 ice_find_seg_in_pkg (hw , SEGMENT_TYPE_ICE_RUN_TIME_CFG , pkg_hdr );
24332429 if (!seg ) {
24342430 ice_debug (hw , ICE_DBG_INIT , "5 layer topology segment is missing\n" );
@@ -2461,8 +2457,10 @@ int ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len)
24612457 return - EIO ;
24622458 }
24632459
2464- /* Get the new topology buffer */
2465- new_topo = ((u8 * )section ) + offset ;
2460+ /* Get the new topology buffer, reuse current topo copy mem */
2461+ static_assert (ICE_PKG_BUF_SIZE == ICE_AQ_MAX_BUF_LEN );
2462+ new_topo = topo ;
2463+ memcpy (new_topo , (u8 * )section + offset , size );
24662464
24672465update_topo :
24682466 /* Acquire global lock to make sure that set topology issued
0 commit comments