Use the FLEX_ARRAY_SIZE() helper with the recently added flexible array
members in structures.

Signed-off-by: Bruce Allan <bruce.w.al...@intel.com>
Signed-off-by: Qi Zhang <qi.z.zh...@intel.com>
---
 drivers/net/ice/base/ice_common.c    | 2 +-
 drivers/net/ice/base/ice_flex_pipe.c | 2 +-
 drivers/net/ice/base/ice_type.h      | 4 ++++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ice/base/ice_common.c 
b/drivers/net/ice/base/ice_common.c
index 2a9185f570..0c1259b42a 100644
--- a/drivers/net/ice/base/ice_common.c
+++ b/drivers/net/ice/base/ice_common.c
@@ -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);
diff --git a/drivers/net/ice/base/ice_flex_pipe.c 
b/drivers/net/ice/base/ice_flex_pipe.c
index 4a27061b3d..7594df1696 100644
--- a/drivers/net/ice/base/ice_flex_pipe.c
+++ b/drivers/net/ice/base/ice_flex_pipe.c
@@ -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;
diff --git a/drivers/net/ice/base/ice_type.h b/drivers/net/ice/base/ice_type.h
index 7545235635..f93baed8d9 100644
--- a/drivers/net/ice/base/ice_type.h
+++ b/drivers/net/ice/base/ice_type.h
@@ -44,6 +44,10 @@
 #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"
-- 
2.25.4

Reply via email to