Re: [PATCH v4 27/27] net/ice: avoid rte malloc in flow pattern match

Bruce Richardson
2026-02-16T17:37:54Z

On Fri, Feb 13, 2026 at 10:26:38AM +0000, Anatoly Burakov wrote:
> Currently, when allocating buffers for pattern match items and flow item
> storage, we are using rte_zmalloc followed by immediate rte_free. This is
> not needed as these buffers are only used temporarily within the function
> scope, so replace it with regular calloc/free.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
> drivers/net/intel/ice/ice_acl_filter.c | 3 ++-
> drivers/net/intel/ice/ice_fdir_filter.c | 5 +++--
> drivers/net/intel/ice/ice_generic_flow.c | 15 +++++++--------
> drivers/net/intel/ice/ice_hash.c | 3 ++-
> drivers/net/intel/ice/ice_switch_filter.c | 5 +++--
> 5 files changed, 17 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/net/intel/ice/ice_acl_filter.c b/drivers/net/intel/ice/ice_acl_filter.c
> index 38e30a4f62..6754a40044 100644
> --- a/drivers/net/intel/ice/ice_acl_filter.c
> +++ b/drivers/net/intel/ice/ice_acl_filter.c
> @@ -9,6 +9,7 @@
> #include <string.h>
> #include <unistd.h>
> #include <stdarg.h>
> +#include <stdlib.h>
> #include <rte_debug.h>
> #include <rte_ether.h>
> #include <ethdev_driver.h>
> @@ -1009,7 +1010,7 @@ ice_acl_parse(struct ice_adapter *ad,
> *meta = filter;
>
> error:
> - rte_free(item);
> + free(item);
> return ret;
> }

Should this code be reworked so that the error is propagated back to caller
and the item freed there so as allocation and freeing occur together in the
one function - or even in the same file?

>
> diff --git a/drivers/net/intel/ice/ice_fdir_filter.c b/drivers/net/intel/ice/ice_fdir_filter.c
> index 5f44b5c818..8cca831fa9 100644
> --- a/drivers/net/intel/ice/ice_fdir_filter.c
> +++ b/drivers/net/intel/ice/ice_fdir_filter.c
> @@ -3,6 +3,7 @@
> */
>
> #include <stdio.h>
> +#include <stdlib.h>
> #include <rte_flow.h>
> #include <rte_hash.h>
> #include <rte_hash_crc.h>
> @@ -2504,11 +2505,11 @@ ice_fdir_parse(struct ice_adapter *ad,
> rte_free(filter->pkt_buf);
> }
>
> - rte_free(item);
> + free(item);
> return ret;
> error:
> rte_free(filter->pkt_buf);
> - rte_free(item);
> + free(item);
> return ret;
> }
>
> diff --git a/drivers/net/intel/ice/ice_generic_flow.c b/drivers/net/intel/ice/ice_generic_flow.c
> index 4049157eab..3f7a9f4714 100644
> --- a/drivers/net/intel/ice/ice_generic_flow.c
> +++ b/drivers/net/intel/ice/ice_generic_flow.c
> @@ -9,6 +9,7 @@
> #include <string.h>
> #include <unistd.h>
> #include <stdarg.h>
> +#include <stdlib.h>
>
> #include <rte_ether.h>
> #include <ethdev_driver.h>
> @@ -2136,19 +2137,17 @@ ice_search_pattern_match_item(struct ice_adapter *ad,
> }
> item_num++;
>
> - items = rte_zmalloc("ice_pattern",
> - item_num * sizeof(struct rte_flow_item), 0);
> + items = calloc(item_num, sizeof(struct rte_flow_item));
> if (!items) {

<snip for brevity>