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")
Cc: sta...@dpdk.org

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  | 10 ++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 11 ++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev.c 
b/drivers/event/cnxk/cnxk_eventdev.c
index 84a55511a328..feb23e0b2177 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -482,7 +482,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 +491,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 +519,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 +529,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 bba70646fa16..63f868bdb33d 100644
--- a/drivers/event/cnxk/cnxk_tim_evdev.c
+++ b/drivers/event/cnxk/cnxk_tim_evdev.c
@@ -420,7 +420,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;
 
@@ -431,7 +432,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++;
        }
 
@@ -507,16 +508,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.22.0

Reply via email to