From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B5BF9A04DD; Wed, 21 Oct 2020 00:50:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 56BE5AD22; Wed, 21 Oct 2020 00:45:38 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 0DD88ACEC for ; Wed, 21 Oct 2020 00:45:18 +0200 (CEST) IronPort-SDR: nNfsRhcYvMjFXVdbEl2HIwT5TWJXkCRLrLlK+MWxzIGI1FeRDgI2bGAwwfQ1I0hs6ylZhZLACC snDqoF6z1gSQ== X-IronPort-AV: E=McAfee;i="6000,8403,9780"; a="166510636" X-IronPort-AV: E=Sophos;i="5.77,399,1596524400"; d="scan'208";a="166510636" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2020 15:45:17 -0700 IronPort-SDR: OfU7Iekkct+Tp+MddrTM+gOqJtgne1x/uHSFshgmP2mC8oB7//OYa6vAhskh68qeD8tnhqc2E2 Hwt1In5j64YQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,399,1596524400"; d="scan'208";a="533254717" Received: from dpdk51.sh.intel.com ([10.67.111.142]) by orsmga005.jf.intel.com with ESMTP; 20 Oct 2020 15:45:16 -0700 From: Qi Zhang To: qiming.yang@intel.com Cc: dev@dpdk.org, Qi Zhang , Bruce Allan Date: Wed, 21 Oct 2020 06:48:43 +0800 Message-Id: <20201020224846.1592682-19-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201020224846.1592682-1-qi.z.zhang@intel.com> References: <20201020224846.1592682-1-qi.z.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 18/21] net/ice/base: introduce and use FLEX_ARRAY_SIZE where possible X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use the FLEX_ARRAY_SIZE() helper with the recently added flexible array members in structures. Signed-off-by: Bruce Allan Signed-off-by: Qi Zhang --- 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