From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 87554A04FF; Tue, 22 Mar 2022 15:44:05 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1A8F340E64; Tue, 22 Mar 2022 15:44:05 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 950CA40694; Tue, 22 Mar 2022 15:44:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647960243; x=1679496243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YSLin5Q81jnMIFFRgagVXjUt03ihqZu9LzMn5Jzuuhs=; b=jwiXC8ZBiba6bI2ZEUxYSex1cfCMRxch6xkkofcf0dFwNcjzkLDSoY9V x/CqihR4dlWvSXH/lOTN35TtAOHIakdRCVqZufFF3MLTnV5rFohJLyVg8 WkDcEicoD6TUxDKuRUg8dH+uNR4cuzr0JSAgYnmY0GBp9xBWIwRCIBec9 gYLQSeOcOQDZADGcwEMTzJqqb60k+jwpD164m+pcCLS14Auvix0AtJ8Sq H2sdQw50yimpbXt/BXqbGXJOljhMa/LXwJX/O/wKESfI5YCjCHxzCFAtx MgWb4nPDpFIWZePAFq1miFBa9EA8aryuGFlzS4AE1eUIJTX9ZunmHnNYH w==; X-IronPort-AV: E=McAfee;i="6200,9189,10294"; a="245307054" X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="245307054" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2022 07:44:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,201,1643702400"; d="scan'208";a="583282413" Received: from silpixa00400214.ir.intel.com (HELO silpixa00400214.ger.corp.intel.com) ([10.237.223.184]) by orsmga001.jf.intel.com with ESMTP; 22 Mar 2022 07:44:00 -0700 From: Shibin Koikkara Reeny To: david.hunt@intel.com Cc: dev@dpdk.org, Shibin Koikkara Reeny , alan.carew@intel.com, stable@dpdk.org Subject: [PATCH v3] examples/vm_power: add support for list_foreach_safe Date: Tue, 22 Mar 2022 14:43:56 +0000 Message-Id: <20220322144356.1258169-1-shibin.koikkara.reeny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220321093342.1223208-1-shibin.koikkara.reeny@intel.com> References: <20220321093342.1223208-1-shibin.koikkara.reeny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE. Added support for LIST_FOREACH_SAFE macro in rte_os.h file as Linux header file sys/queue.h don't support LIST_FOREACH_SAFE macro. RTE_LIST_FOREACH_SAFE is alias for LIST_FOREACH_SAFE. Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host") Cc: alan.carew@intel.com Cc: stable@dpdk.org Signed-off-by: Shibin Koikkara Reeny --- v3: add blank line after declaration v2: add support for list_foreach_safe --- examples/vm_power_manager/channel_manager.c | 10 ++++++---- lib/eal/linux/include/rte_os.h | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 838465ab4b..2d54641f2e 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -66,8 +66,9 @@ LIST_HEAD(, virtual_machine_info) vm_list_head; static struct virtual_machine_info * find_domain_by_name(const char *name) { - struct virtual_machine_info *info; - LIST_FOREACH(info, &vm_list_head, vms_info) { + struct virtual_machine_info *info, *t_info; + + RTE_LIST_FOREACH_SAFE(info, &vm_list_head, vms_info, t_info) { if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1)) return info; } @@ -1005,9 +1006,9 @@ channel_manager_exit(void) { unsigned i; char mask[RTE_MAX_LCORE]; - struct virtual_machine_info *vm_info; + struct virtual_machine_info *vm_info, *t_info; - LIST_FOREACH(vm_info, &vm_list_head, vms_info) { + RTE_LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, t_info) { rte_spinlock_lock(&(vm_info->config_spinlock)); @@ -1024,6 +1025,7 @@ channel_manager_exit(void) LIST_REMOVE(vm_info, vms_info); rte_free(vm_info); + } if (global_hypervisor_available) { diff --git a/lib/eal/linux/include/rte_os.h b/lib/eal/linux/include/rte_os.h index c72bf5b7e6..3acff49360 100644 --- a/lib/eal/linux/include/rte_os.h +++ b/lib/eal/linux/include/rte_os.h @@ -25,6 +25,8 @@ extern "C" { #define RTE_TAILQ_NEXT(elem, field) TAILQ_NEXT(elem, field) #define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type) #define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type) +#define RTE_LIST_FIRST(head) LIST_FIRST(head) +#define RTE_LIST_NEXT(elem, field) LIST_NEXT(elem, field) #ifdef CPU_SETSIZE /* may require _GNU_SOURCE */ typedef cpu_set_t rte_cpuset_t; @@ -46,6 +48,15 @@ typedef cpu_set_t rte_cpuset_t; } while (0) #endif +#ifndef LIST_FOREACH_SAFE +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = RTE_LIST_FIRST(head); \ + (var) && ((tvar) = RTE_LIST_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif +#define RTE_LIST_FOREACH_SAFE(var, head, field, tvar) \ + LIST_FOREACH_SAFE(var, head, field, tvar) + #ifdef __cplusplus } #endif -- 2.25.1