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: 9ccb76b24c1d ("bus/fslmc: enable portal interrupt handling")
Fixes: 828d51d8fc3e ("bus/fslmc: refactor scan and probe functions")
Cc: sta...@dpdk.org

Signed-off-by: Jie Hai <haij...@huawei.com>
Acked-by: Chengwen Feng <fengcheng...@huawei.com>
---
 drivers/bus/fslmc/fslmc_bus.c            | 5 +++--
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 57bfb5111a97..2aa0e45c3d1b 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -131,6 +131,7 @@ scan_one_fslmc_device(char *dev_name)
 {
        char *dup_dev_name, *t_ptr;
        struct rte_dpaa2_device *dev = NULL;
+       char *sp = NULL;
        int ret = -1;
 
        if (!dev_name)
@@ -168,7 +169,7 @@ scan_one_fslmc_device(char *dev_name)
        }
 
        /* Parse the device name and ID */
-       t_ptr = strtok(dup_dev_name, ".");
+       t_ptr = strtok_s(dup_dev_name, ".", &sp);
        if (!t_ptr) {
                DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
                ret = -EINVAL;
@@ -199,7 +200,7 @@ scan_one_fslmc_device(char *dev_name)
        else
                dev->dev_type = DPAA2_UNKNOWN;
 
-       t_ptr = strtok(NULL, ".");
+       t_ptr = strtok_s(NULL, ".", &sp);
        if (!t_ptr) {
                DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
                ret = 0;
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c 
b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 4aec7b2cd8ba..b788d7681866 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -129,7 +129,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, 
int cpu_id)
        uint32_t cpu_mask = 1;
        int ret;
        size_t len = 0;
-       char *temp = NULL, *token = NULL;
+       char *temp = NULL, *token = NULL, *sp = NULL;
        char string[STRING_LEN], command[COMMAND_LEN];
        FILE *file;
 
@@ -141,7 +141,7 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, 
int cpu_id)
        }
        while (getline(&temp, &len, file) != -1) {
                if ((strstr(temp, string)) != NULL) {
-                       token = strtok(temp, ":");
+                       token = strtok_s(temp, ":", &sp);
                        break;
                }
        }
-- 
2.30.0

Reply via email to