DPDK patches and discussions
 help / color / mirror / Atom feed
From: Qi Zhang <qi.z.zhang@intel.com>
To: qiming.yang@intel.com
Cc: dev@dpdk.org, Qi Zhang <qi.z.zhang@intel.com>,
	Bruce Allan <bruce.w.allan@intel.com>
Subject: [dpdk-dev] [PATCH v2 18/21] net/ice/base: introduce and use FLEX_ARRAY_SIZE where possible
Date: Sun, 25 Oct 2020 08:29:50 +0800
Message-ID: <20201025002953.1680999-19-qi.z.zhang@intel.com> (raw)
In-Reply-To: <20201025002953.1680999-1-qi.z.zhang@intel.com>

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>
---
 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


  parent reply	other threads:[~2020-10-25  0:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-25  0:29 [dpdk-dev] [PATCH v2 00/21] ice: update base code Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 01/21] net/ice/base: add tunnel support for FDIR Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 02/21] net/ice/base: add NVM Write Response flags Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 03/21] net/ice/base: modify ptype bitmap for outer MAC Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 04/21] net/ice/base: rename ptype bitmap Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 05/21] net/ice/base: move sched function prototypes Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 06/21] net/ice/base: read security revision Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 07/21] net/ice/base: add functions to allocate and free a RSS global LUT Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 08/21] net/ice/base: add more capability to admin queue Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 09/21] net/ice/base: update to use package info from ice segment Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 10/21] net/ice/base: use malloc instead of calloc Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 11/21] net/ice/base: add support for class 5+ modules Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 12/21] net/ice/base: return error directly Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 13/21] net/ice/base: implement shared rate limiter Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 14/21] net/ice/base: recognize 860 as iSCSI port in CEE mode Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 15/21] net/ice/base: fix parameter name in comment Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 16/21] net/ice/base: support extended GPIO access Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 17/21] net/ice/base: remove duplicated AQ command flag setting Qi Zhang
2020-10-25  0:29 ` Qi Zhang [this message]
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 19/21] net/ice/base: refactor RSS configure API Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 20/21] net/ice/base: add support for get/set RSS LUT to specify global LUT Qi Zhang
2020-10-25  0:29 ` [dpdk-dev] [PATCH v2 21/21] net/ice/base: update version Qi Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201025002953.1680999-19-qi.z.zhang@intel.com \
    --to=qi.z.zhang@intel.com \
    --cc=bruce.w.allan@intel.com \
    --cc=dev@dpdk.org \
    --cc=qiming.yang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git