[v2] examples/vm_power: add support for list_foreach_safe

Message ID 20220321093342.1223208-1-shibin.koikkara.reeny@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] examples/vm_power: add support for list_foreach_safe |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues

Commit Message

Koikkara Reeny, Shibin March 21, 2022, 9:33 a.m. UTC
  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 <shibin.koikkara.reeny@intel.com>
---
 examples/vm_power_manager/channel_manager.c |  9 +++++----
 lib/eal/linux/include/rte_os.h              | 11 +++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
  

Comments

Stephen Hemminger March 21, 2022, 4:16 p.m. UTC | #1
On Mon, 21 Mar 2022 09:33:42 +0000
Shibin Koikkara Reeny <shibin.koikkara.reeny@intel.com> wrote:

> diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
> index 838465ab4b..d297b28114 100644
> --- a/examples/vm_power_manager/channel_manager.c
> +++ b/examples/vm_power_manager/channel_manager.c
> @@ -66,8 +66,8 @@ 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))

Please add blank line after declarations. It didn't have it before but
is better style.
  

Patch

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 838465ab4b..d297b28114 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -66,8 +66,8 @@  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 +1005,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 +1024,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