diff mbox

[dpdk-dev,v2,1/3] devargs: indent and cleanup

Message ID 1423839795-29450-2-git-send-email-david.marchand@6wind.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

David Marchand Feb. 13, 2015, 3:03 p.m. UTC
Prepare for next commit.
Fix some indent issues, refactor error code.

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
diff mbox

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 4c7d11a..8c9b31a 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -48,7 +48,7 @@  struct rte_devargs_list devargs_list =
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
-	struct rte_devargs *devargs;
+	struct rte_devargs *devargs = NULL;
 	char buf[RTE_DEVARGS_LEN];
 	char *sep;
 	int ret;
@@ -57,14 +57,14 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	if (ret < 0 || ret >= (int)sizeof(buf)) {
 		RTE_LOG(ERR, EAL, "user device args too large: <%s>\n",
 			devargs_str);
-		return -1;
+		goto fail;
 	}
 
 	/* use malloc instead of rte_malloc as it's called early at init */
 	devargs = malloc(sizeof(*devargs));
 	if (devargs == NULL) {
 		RTE_LOG(ERR, EAL, "cannot allocate devargs\n");
-		return -1;
+		goto fail;
 	}
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
@@ -81,28 +81,29 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	case RTE_DEVTYPE_BLACKLISTED_PCI:
 		/* try to parse pci identifier */
 		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
-			eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0) {
-			RTE_LOG(ERR, EAL,
-				"invalid PCI identifier <%s>\n", buf);
-			free(devargs);
-			return -1;
+		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0) {
+			RTE_LOG(ERR, EAL, "invalid PCI identifier <%s>\n", buf);
+			goto fail;
 		}
 		break;
 	case RTE_DEVTYPE_VIRTUAL:
 		/* save driver name */
 		ret = snprintf(devargs->virtual.drv_name,
-			sizeof(devargs->virtual.drv_name), "%s", buf);
+			       sizeof(devargs->virtual.drv_name), "%s", buf);
 		if (ret < 0 || ret >= (int)sizeof(devargs->virtual.drv_name)) {
-			RTE_LOG(ERR, EAL,
-				"driver name too large: <%s>\n", buf);
-			free(devargs);
-			return -1;
+			RTE_LOG(ERR, EAL, "driver name too large: <%s>\n", buf);
+			goto fail;
 		}
 		break;
 	}
 
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
+
+fail:
+	if (devargs)
+		free(devargs);
+	return -1;
 }
 
 /* count the number of devices of a specified type */