examples/vm_power: replace list foreach with while loop
Checks
Commit Message
Linux header files don't support LIST_FOREACH_SAFE so replacing
LIST_FOREACH with while loop.
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 | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Comments
01/03/2022 15:53, Shibin Koikkara Reeny:
> Linux header files don't support LIST_FOREACH_SAFE so replacing
> LIST_FOREACH with while loop.
What is the original issue you are trying to solve?
> - struct virtual_machine_info *vm_info;
> -
> - LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
> + struct virtual_machine_info *vm_info = LIST_FIRST(&vm_list_head);
>
> + /* No LIST_FOREACH_SAFE, using while instead. */
> + while (vm_info) {
> rte_spinlock_lock(&(vm_info->config_spinlock));
>
> memcpy(mask, (char *)vm_info->channel_mask, RTE_MAX_LCORE);
> @@ -1024,6 +1024,8 @@ channel_manager_exit(void)
>
> LIST_REMOVE(vm_info, vms_info);
> rte_free(vm_info);
> +
> + vm_info = LIST_NEXT((vm_info), vms_info);
> }
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> 01/03/2022 15:53, Shibin Koikkara Reeny:
> > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > LIST_FOREACH with while loop.
>
> What is the original issue you are trying to solve?
Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but
Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.
Regards,
Shibin
10/03/2022 10:32, Koikkara Reeny, Shibin:
> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > 01/03/2022 15:53, Shibin Koikkara Reeny:
> > > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > > LIST_FOREACH with while loop.
> >
> > What is the original issue you are trying to solve?
> Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but
> Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.
This explanation should be in the commit log please.
On Thu, 10 Mar 2022 09:32:08 +0000
"Koikkara Reeny, Shibin" <shibin.koikkara.reeny@intel.com> wrote:
> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > 01/03/2022 15:53, Shibin Koikkara Reeny:
> > > Linux header files don't support LIST_FOREACH_SAFE so replacing
> > > LIST_FOREACH with while loop.
> >
> > What is the original issue you are trying to solve?
> Asan tool reported LIST_FOREACH should be replaced with LIST_FOREACH_SAFE but
> Linux don't have LIST_FOREACH_SAFE API. So replacing it with while loop.
>
> Regards,
> Shibin
Why not just clone LIST_FOREACH_SAFE from BSD?
That is what RTE_TAILQ does.
It might be generally useful.
@@ -1005,10 +1005,10 @@ channel_manager_exit(void)
{
unsigned i;
char mask[RTE_MAX_LCORE];
- struct virtual_machine_info *vm_info;
-
- LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
+ struct virtual_machine_info *vm_info = LIST_FIRST(&vm_list_head);
+ /* No LIST_FOREACH_SAFE, using while instead. */
+ while (vm_info) {
rte_spinlock_lock(&(vm_info->config_spinlock));
memcpy(mask, (char *)vm_info->channel_mask, RTE_MAX_LCORE);
@@ -1024,6 +1024,8 @@ channel_manager_exit(void)
LIST_REMOVE(vm_info, vms_info);
rte_free(vm_info);
+
+ vm_info = LIST_NEXT((vm_info), vms_info);
}
if (global_hypervisor_available) {