The cleanup loop would deference the dpio_dev after freeing.
Use TAILQ_FOREACH_SAFE to fix that.
Found by building with sanitizer undefined flag.

Fixes: e55d0494ab98 ("bus/fslmc: support secondary process")
Cc: shreyansh.j...@nxp.com
Cc: sta...@dpdk.org
Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
Acked-by: Hemant Agrawal <hemant.agra...@nxp.com>
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c 
b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 2dfcf7a498..bc03b4dd05 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -38,6 +38,13 @@
 #include "dpaa2_hw_dpio.h"
 #include <mc/fsl_dpmng.h>
 
+#ifndef TAILQ_FOREACH_SAFE
+#define        TAILQ_FOREACH_SAFE(var, head, field, tvar)                      
\
+       for ((var) = TAILQ_FIRST((head));                               \
+           (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
+           (var) = (tvar))
+#endif
+
 #define NUM_HOST_CPUS RTE_MAX_LCORE
 
 struct dpaa2_io_portal_t dpaa2_io_portal[RTE_MAX_LCORE];
@@ -403,6 +410,7 @@ dpaa2_create_dpio_device(int vdev_fd,
        struct rte_dpaa2_device *obj)
 {
        struct dpaa2_dpio_dev *dpio_dev = NULL;
+       struct dpaa2_dpio_dev *dpio_tmp;
        struct vfio_region_info reg_info = { .argsz = sizeof(reg_info)};
        struct qbman_swp_desc p_des;
        struct dpio_attr attr;
@@ -588,7 +596,7 @@ dpaa2_create_dpio_device(int vdev_fd,
        rte_free(dpio_dev);
 
        /* For each element in the list, cleanup */
-       TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) {
+       TAILQ_FOREACH_SAFE(dpio_dev, &dpio_dev_list, next, dpio_tmp) {
                if (dpio_dev->dpio) {
                        dpio_disable(dpio_dev->dpio, CMD_PRI_LOW,
                                dpio_dev->token);
-- 
2.47.2

Reply via email to