[v6,18/25] raw/cnxk_gpio: replace strtok with reentrant version

Message ID 20241122110458.2156907-19-haijie1@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series replace strtok with strtok_r |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 22, 2024, 11:04 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: ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
Cc: stable@dpdk.org

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

Patch

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;