]> git.droids-corp.org - dpdk.git/commitdiff
net/ice/base: use struct size helper
authorQi Zhang <qi.z.zhang@intel.com>
Mon, 23 Mar 2020 07:17:30 +0000 (15:17 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 21 Apr 2020 11:57:04 +0000 (13:57 +0200)
For structures using the common C "struct hack" technique to create a
flexible length structure member at the end of the structure, use the
ice_struct_size macro to determine the length of the structure instead
of open coding the calculation.

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>
Acked-by: Qiming Yang <qiming.yang@intel.com>
drivers/net/ice/base/ice_common.c
drivers/net/ice/base/ice_flex_pipe.c
drivers/net/ice/base/ice_sched.c
drivers/net/ice/base/ice_type.h

index 9ef1aeef2cf95e1281813cc33e66e2e76ee75bf8..4b1b3106637a8c66aca8f4813081e2963c90918f 100644 (file)
@@ -1680,7 +1680,7 @@ ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
        enum ice_status status;
        u16 buf_len;
 
-       buf_len = sizeof(*buf) + sizeof(buf->elem) * (num - 1);
+       buf_len = ice_struct_size(buf, elem, num - 1);
        buf = (struct ice_aqc_alloc_free_res_elem *)
                ice_malloc(hw, buf_len);
        if (!buf)
@@ -1720,7 +1720,7 @@ ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
        enum ice_status status;
        u16 buf_len;
 
-       buf_len = sizeof(*buf) + sizeof(buf->elem) * (num - 1);
+       buf_len = ice_struct_size(buf, elem, num - 1);
        buf = (struct ice_aqc_alloc_free_res_elem *)ice_malloc(hw, buf_len);
        if (!buf)
                return ICE_ERR_NO_MEMORY;
index 1598efd67b98d00749811f1f70a8355649ed2ff1..82b27de0e09d3a1360d8982e38599e94e71af19d 100644 (file)
@@ -1136,8 +1136,7 @@ static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
 
        ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
 
-       size = sizeof(*pkg_info) + (sizeof(pkg_info->pkg_info[0]) *
-                                   (ICE_PKG_CNT - 1));
+       size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT - 1);
        pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
        if (!pkg_info)
                return ICE_ERR_NO_MEMORY;
@@ -1209,7 +1208,7 @@ static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
                return ICE_ERR_CFG;
 
        /* make sure segment array fits in package length */
-       if (len < sizeof(*pkg) + ((seg_count - 1) * sizeof(pkg->seg_offset)))
+       if (len < ice_struct_size(pkg, seg_offset, seg_count - 1))
                return ICE_ERR_BUF_TOO_SHORT;
 
        /* all segments must fit within length */
index 740f7c3ffa6bdeee063675ea197412b5960e2c60..03885d0277f486706b7b8863e141192ea77b4bc4 100644 (file)
@@ -899,7 +899,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
        u16 buf_size;
        u32 teid;
 
-       buf_size = sizeof(*buf) + sizeof(*buf->generic) * (num_nodes - 1);
+       buf_size = ice_struct_size(buf, generic, num_nodes - 1);
        buf = (struct ice_aqc_add_elem *)ice_malloc(hw, buf_size);
        if (!buf)
                return ICE_ERR_NO_MEMORY;
index 237220ee8cace75505d29831062588a54fbfa412..59dce32fad9bab7b6909e0963364074176977436 100644 (file)
@@ -34,6 +34,9 @@
 
 #define IS_ASCII(_ch)  ((_ch) < 0x80)
 
+#define ice_struct_size(ptr, field, num) \
+       (sizeof(*(ptr)) + sizeof(*(ptr)->field) * (num))
+
 #include "ice_status.h"
 #include "ice_hw_autogen.h"
 #include "ice_devids.h"