[PATCH v5 19/25] raw/cnxk_gpio: replace strtok with reentrant version

Jie Hai haijie1 at huawei.com
Fri Nov 8 12:03:58 CET 2024


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: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: stable at dpdk.org

Signed-off-by: Jie Hai <haijie1 at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 329ac28a2736..e6408db824de 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -11,6 +11,7 @@
 #include <rte_kvargs.h>
 #include <rte_lcore.h>
 #include <rte_rawdev_pmd.h>
+#include <rte_os_shim.h>
 
 #include <roc_api.h>
 
@@ -192,7 +193,7 @@ static int
 cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 {
 	int i, ret, val, queue = 0;
-	char *token;
+	char *token, *sp = NULL;
 	int *list;
 
 	list = rte_calloc(NULL, gpiochip->num_gpios, sizeof(*list), 0);
@@ -210,7 +211,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 	allowlist[strlen(allowlist) - 1] = ' ';
 
 	/* quiesce -Wcast-qual */
-	token = strtok((char *)(uintptr_t)allowlist, ",");
+	token = strtok_r((char *)(uintptr_t)allowlist, ",", &sp);
 	do {
 		errno = 0;
 		val = strtol(token, NULL, 10);
@@ -236,7 +237,7 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip, char *allowlist)
 		}
 		if (i == queue)
 			list[queue++] = val;
-	} while ((token = strtok(NULL, ",")));
+	} while ((token = strtok_r(NULL, ",", &sp)));
 
 	free(allowlist);
 	gpiochip->allowlist = list;
-- 
2.22.0



More information about the dev mailing list