[PATCH v4 11/13] raw/cnxk_gpio: replace strtok with reentrant version
Jie Hai
haijie1 at huawei.com
Sat Oct 26 12:14:49 CEST 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 | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 329ac28a2736..bad70ecb1985 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -192,7 +192,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 +210,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 +236,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