New upstream version 18.11.2
[deb_dpdk.git] / drivers / bus / fslmc / fslmc_bus.c
index 89af938..776b7ca 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  *
- *   Copyright 2016 NXP
+ *   Copyright 2016,2018 NXP
  *
  */
 
@@ -195,7 +195,7 @@ scan_one_fslmc_device(char *dev_name)
 
        t_ptr = strtok(NULL, ".");
        if (!t_ptr) {
-               DPAA2_BUS_ERR("Incorrect device string observed (%s)", t_ptr);
+               DPAA2_BUS_ERR("Incorrect device string observed (null)");
                goto cleanup;
        }
 
@@ -227,20 +227,16 @@ static int
 rte_fslmc_parse(const char *name, void *addr)
 {
        uint16_t dev_id;
-       char *t_ptr;
-       char *sep = strchr(name, ':');
+       char *t_ptr = NULL, *dname = NULL;
 
-       if (strncmp(name, RTE_STR(FSLMC_BUS_NAME),
-               strlen(RTE_STR(FSLMC_BUS_NAME)))) {
-               return -EINVAL;
-       }
+       /* 'name' is expected to contain name of device, for example, dpio.1,
+        * dpni.2, etc.
+        */
 
-       if (!sep) {
-               DPAA2_BUS_ERR("Incorrect device name observed");
+       dname = strdup(name);
+       if (!dname)
                return -EINVAL;
-       }
-
-       t_ptr = (char *)(sep + 1);
+       t_ptr = dname;
 
        if (strncmp("dpni", t_ptr, 4) &&
            strncmp("dpseci", t_ptr, 6) &&
@@ -250,25 +246,30 @@ rte_fslmc_parse(const char *name, void *addr)
            strncmp("dpci", t_ptr, 4) &&
            strncmp("dpmcp", t_ptr, 5) &&
            strncmp("dpdmai", t_ptr, 6)) {
-               DPAA2_BUS_ERR("Unknown or unsupported device");
-               return -EINVAL;
+               DPAA2_BUS_DEBUG("Unknown or unsupported device (%s)", name);
+               goto err_out;
        }
 
        t_ptr = strchr(name, '.');
        if (!t_ptr) {
-               DPAA2_BUS_ERR("Incorrect device string observed (%s)", t_ptr);
-               return -EINVAL;
+               DPAA2_BUS_ERR("Incorrect device string observed (null)");
+               goto err_out;
        }
 
        t_ptr = (char *)(t_ptr + 1);
        if (sscanf(t_ptr, "%hu", &dev_id) <= 0) {
                DPAA2_BUS_ERR("Incorrect device string observed (%s)", t_ptr);
-               return -EINVAL;
+               goto err_out;
        }
+       free(dname);
 
        if (addr)
-               strcpy(addr, (char *)(sep + 1));
+               strcpy(addr, name);
+
        return 0;
+err_out:
+       free(dname);
+       return -EINVAL;
 }
 
 static int
@@ -293,8 +294,8 @@ rte_fslmc_scan(void)
                goto scan_fail;
 
        /* Scan devices on the group */
-       sprintf(fslmc_dirpath, "%s/%d/devices", VFIO_IOMMU_GROUP_PATH,
-               groupid);
+       snprintf(fslmc_dirpath, sizeof(fslmc_dirpath), "%s/%d/devices",
+                       VFIO_IOMMU_GROUP_PATH, groupid);
        dir = opendir(fslmc_dirpath);
        if (!dir) {
                DPAA2_BUS_ERR("Unable to open VFIO group directory");