net/ice/base: use macro to get variable size array length
authorQi Zhang <qi.z.zhang@intel.com>
Tue, 20 Oct 2020 01:33:53 +0000 (09:33 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:35:03 +0000 (23:35 +0100)
Use the FLEX_ARRAY_SIZE() helper with the recently added flexible array
members in structures.

Signed-off-by: Bruce Allan <bruce.w.allan@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_type.h

index 2a9185f..0c1259b 100644 (file)
@@ -1704,7 +1704,7 @@ ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,
        if (!buf)
                return ICE_ERR_PARAM;
 
-       if (buf_size < (num_entries * sizeof(buf->elem[0])))
+       if (buf_size < FLEX_ARRAY_SIZE(buf, elem, num_entries))
                return ICE_ERR_PARAM;
 
        ice_fill_dflt_direct_cmd_desc(&desc, opc);
index 4a27061..7594df1 100644 (file)
@@ -1833,7 +1833,7 @@ ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
        bld->reserved_section_table_entries += count;
 
        data_end = LE16_TO_CPU(buf->data_end) +
-                  (count * sizeof(buf->section_entry[0]));
+               FLEX_ARRAY_SIZE(buf, section_entry, count);
        buf->data_end = CPU_TO_LE16(data_end);
 
        return ICE_SUCCESS;
index 7545235..f93baed 100644 (file)
 #define ice_struct_size(ptr, field, num) \
        (sizeof(*(ptr)) + sizeof(*(ptr)->field) * (num))
 
+#ifndef FLEX_ARRAY_SIZE
+#define FLEX_ARRAY_SIZE(_ptr, _mem, cnt) ((cnt) * sizeof(_ptr->_mem[0]))
+#endif /* FLEX_ARRAY_SIZE */
+
 #include "ice_status.h"
 #include "ice_hw_autogen.h"
 #include "ice_devids.h"