bus/fslmc: enhance error handling for dev parsing
authorShreyansh Jain <shreyansh.jain@nxp.com>
Mon, 15 Jul 2019 08:44:39 +0000 (14:14 +0530)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 15 Jul 2019 21:48:10 +0000 (23:48 +0200)
In case an incorrect device is found, it was quiting further search
rather than skipping it.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
drivers/bus/fslmc/fslmc_bus.c

index 35103d2..a2ed3bc 100644 (file)
@@ -33,7 +33,7 @@ uint8_t dpaa2_virt_mode;
 uint32_t
 rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)
 {
-       if (device_type > DPAA2_DEVTYPE_MAX)
+       if (device_type >= DPAA2_DEVTYPE_MAX)
                return 0;
        return rte_fslmc_bus.device_count[device_type];
 }
@@ -135,10 +135,11 @@ static int
 scan_one_fslmc_device(char *dev_name)
 {
        char *dup_dev_name, *t_ptr;
-       struct rte_dpaa2_device *dev;
+       struct rte_dpaa2_device *dev = NULL;
+       int ret = -1;
 
        if (!dev_name)
-               return -1;
+               return ret;
 
        /* Ignore the Container name itself */
        if (!strncmp("dprc", dev_name, 4))
@@ -168,7 +169,8 @@ scan_one_fslmc_device(char *dev_name)
        /* Parse the device name and ID */
        t_ptr = strtok(dup_dev_name, ".");
        if (!t_ptr) {
-               DPAA2_BUS_ERR("Incorrect device name observed");
+               DPAA2_BUS_ERR("Invalid device found: (%s)", dup_dev_name);
+               ret = -EINVAL;
                goto cleanup;
        }
        if (!strncmp("dpni", t_ptr, 4))
@@ -192,12 +194,10 @@ scan_one_fslmc_device(char *dev_name)
        else
                dev->dev_type = DPAA2_UNKNOWN;
 
-       /* Update the device found into the device_count table */
-       rte_fslmc_bus.device_count[dev->dev_type]++;
-
        t_ptr = strtok(NULL, ".");
        if (!t_ptr) {
-               DPAA2_BUS_ERR("Incorrect device string observed (null)");
+               DPAA2_BUS_ERR("Skipping invalid device (%s)", dup_dev_name);
+               ret = 0;
                goto cleanup;
        }
 
@@ -205,10 +205,14 @@ scan_one_fslmc_device(char *dev_name)
        dev->device.name = strdup(dev_name);
        if (!dev->device.name) {
                DPAA2_BUS_ERR("Unable to clone device name. Out of memory");
+               ret = -ENOMEM;
                goto cleanup;
        }
        dev->device.devargs = fslmc_devargs_lookup(dev);
 
+       /* Update the device found into the device_count table */
+       rte_fslmc_bus.device_count[dev->dev_type]++;
+
        /* Add device in the fslmc device list */
        insert_in_device_list(dev);
 
@@ -222,7 +226,7 @@ cleanup:
                free(dup_dev_name);
        if (dev)
                free(dev);
-       return -1;
+       return ret;
 }
 
 static int
@@ -353,7 +357,7 @@ scan_fail_cleanup:
        /* Remove all devices in the list */
        cleanup_fslmc_device_list();
 scan_fail:
-       DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping");
+       DPAA2_BUS_DEBUG("FSLMC Bus Not Available. Skipping (%d)", ret);
        /* Irrespective of failure, scan only return success */
        return 0;
 }