The TAILQ_FOREACH() macro would refer to info after it
had been freed. Fix by introducing TAILQ_FOREACH_SAFE here.

Fixes: 4a19f89104f8 ("raw/ifpga/base: support multiple cards")
Cc: tianfei.zh...@intel.com
Cc: sta...@dpdk.org

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 drivers/raw/ifpga/base/opae_intel_max10.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/raw/ifpga/base/opae_intel_max10.c 
b/drivers/raw/ifpga/base/opae_intel_max10.c
index dd97a5f9fd..d5a9ceb6e3 100644
--- a/drivers/raw/ifpga/base/opae_intel_max10.c
+++ b/drivers/raw/ifpga/base/opae_intel_max10.c
@@ -6,6 +6,13 @@
 #include <libfdt.h>
 #include "opae_osdep.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
+
 int max10_sys_read(struct intel_max10_device *dev,
        unsigned int offset, unsigned int *val)
 {
@@ -746,9 +753,9 @@ static int fdt_get_named_reg(const void *fdt, int node, 
const char *name,
 
 static void max10_sensor_uinit(struct intel_max10_device *dev)
 {
-       struct opae_sensor_info *info;
+       struct opae_sensor_info *info, *next;
 
-       TAILQ_FOREACH(info, &dev->opae_sensor_list, node) {
+       TAILQ_FOREACH_SAFE(info, &dev->opae_sensor_list, node, next) {
                TAILQ_REMOVE(&dev->opae_sensor_list, info, node);
                opae_free(info);
        }
-- 
2.45.2

Reply via email to