[v5,17/25] event/cnxk: replace strtok with reentrant version

Message ID 20241108110404.18317-18-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series [v5,01/25] app/graph: replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 8, 2024, 11:03 a.m. UTC
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 <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 drivers/event/cnxk/cnxk_eventdev.c  | 11 +++++++----
 drivers/event/cnxk/cnxk_tim_evdev.c | 12 +++++++-----
 2 files changed, 14 insertions(+), 9 deletions(-)
  

Patch

diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c
index 84a55511a328..facbe7fa0928 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -2,6 +2,7 @@ 
  * Copyright(C) 2021 Marvell.
  */
 
+#include <rte_os_shim.h>
 #include "roc_npa.h"
 
 #include "cnxk_eventdev.h"
@@ -482,7 +483,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 +492,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 +520,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 +530,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..82d4a1878dd5 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_npa.h"
 
@@ -420,7 +421,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 +433,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 +509,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++;
 	}