Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

The strtok() is non-reentrant, it is better to replace it with a
reentrant version.

Fixes: 8a3d58c189fd ("event/cnxk: add option to control timer adapters")
Fixes: 8bdbae66b299 ("event/cnxk: add external clock support for timer")

Signed-off-by: Jie Hai <haij...@huawei.com>
Acked-by: Chengwen Feng <fengcheng...@huawei.com>
Acked-by: Morten Brørup <m...@smartsharesystems.com>
---
 drivers/event/cnxk/cnxk_eventdev.c  | 12 ++++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 12 +++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev.c 
b/drivers/event/cnxk/cnxk_eventdev.c
index be6a487b590b..047b5250c7c0 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -2,6 +2,8 @@
  * Copyright(C) 2021 Marvell.
  */
 
+#include <rte_os_shim.h>
+
 #include "roc_api.h"
 
 #include "cnxk_eventdev.h"
@@ -482,7 +484,8 @@ parse_queue_param(char *value, void *opaque)
        struct cnxk_sso_qos queue_qos = {0};
        uint16_t *val = (uint16_t *)&queue_qos;
        struct cnxk_sso_evdev *dev = opaque;
-       char *tok = strtok(value, "-");
+       char *sp = NULL;
+       char *tok = strtok_r(value, "-", &sp);
        struct cnxk_sso_qos *old_ptr;
 
        if (!strlen(value))
@@ -490,7 +493,7 @@ parse_queue_param(char *value, void *opaque)
 
        while (tok != NULL) {
                *val = atoi(tok);
-               tok = strtok(NULL, "-");
+               tok = strtok_r(NULL, "-", &sp);
                val++;
        }
 
@@ -518,7 +521,8 @@ parse_stash_param(char *value, void *opaque)
        struct cnxk_sso_stash queue_stash = {0};
        struct cnxk_sso_evdev *dev = opaque;
        struct cnxk_sso_stash *old_ptr;
-       char *tok = strtok(value, "|");
+       char *sp = NULL;
+       char *tok = strtok_r(value, "|", &sp);
        uint16_t *val;
 
        if (!strlen(value))
@@ -527,7 +531,7 @@ parse_stash_param(char *value, void *opaque)
        val = (uint16_t *)&queue_stash;
        while (tok != NULL) {
                *val = atoi(tok);
-               tok = strtok(NULL, "|");
+               tok = strtok_r(NULL, "|", &sp);
                val++;
        }
 
diff --git a/drivers/event/cnxk/cnxk_tim_evdev.c 
b/drivers/event/cnxk/cnxk_tim_evdev.c
index 994d1d1090e0..245d02a42eff 100644
--- a/drivers/event/cnxk/cnxk_tim_evdev.c
+++ b/drivers/event/cnxk/cnxk_tim_evdev.c
@@ -3,6 +3,7 @@
  */
 
 #include <math.h>
+#include <rte_os_shim.h>
 
 #include "roc_api.h"
 
@@ -455,7 +456,8 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 {
        struct cnxk_tim_evdev *dev = opaque;
        struct cnxk_tim_ctl ring_ctl = {0};
-       char *tok = strtok(value, "-");
+       char *sp = NULL;
+       char *tok = strtok_r(value, "-", &sp);
        struct cnxk_tim_ctl *old_ptr;
        uint16_t *val;
 
@@ -466,7 +468,7 @@ cnxk_tim_parse_ring_param(char *value, void *opaque)
 
        while (tok != NULL) {
                *val = atoi(tok);
-               tok = strtok(NULL, "-");
+               tok = strtok_r(NULL, "-", &sp);
                val++;
        }
 
@@ -542,16 +544,16 @@ cnxk_tim_parse_clk_list(const char *value, void *opaque)
                                      ROC_TIM_CLK_SRC_INVALID};
        struct cnxk_tim_evdev *dev = opaque;
        char *str = strdup(value);
-       char *tok;
+       char *tok, *sp = NULL;
        int i = 0;
 
        if (str == NULL || !strlen(str))
                goto free;
 
-       tok = strtok(str, "-");
+       tok = strtok_r(str, "-", &sp);
        while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
                dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
-               tok = strtok(NULL, "-");
+               tok = strtok_r(NULL, "-", &sp);
                i++;
        }
 
-- 
2.33.0

Reply via email to