From patchwork Wed Oct 30 12:09:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 178113 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp1205501ill; Wed, 30 Oct 2019 05:27:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOLQco0Z7jWLPRO85PnrvTuDBgULqL1Xymm2O4b5RO2wq06D0E/+RfBrlZvJCggl6D7oiF X-Received: by 2002:a17:906:288f:: with SMTP id o15mr8991127ejd.270.1572438452696; Wed, 30 Oct 2019 05:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572438452; cv=none; d=google.com; s=arc-20160816; b=mO77EJ3kAPX6O0oE9KlWzGPgIjzdPSg6dcJJMnjoFnncst/1oa3+AjY5rbV5Lor5Ul KNQIUIHpl4jzut2kf+q7AFm+jXqSi1LIA0O1mxrLUbzkT5K4CVQX5Ru6qCqnO05iy2aB IdEQ8vjTkxoEG1yQDOtNnwFQEiTTCcpm7SlMCBMXiZBQ+X9zLvkW8xlEXDY5wPohSVQW Iustquu3D7IhTqKPF1fAN1XET/l1XTB0wRZcYjkvt4h6oJJC6GtHkbWSTqcbgPhw9Bcd oe00FBrdXY/UF3LiUIrxHxNQ+ndcQ9CypShWrvvP/yko6RnuT4sekemxvi/J/OE9KFC+ DirA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=nRAn7Am7cYNOqFT1ISOglabUmO0/HV4jvxIHRRsLdts=; b=DGNtEPKky15UbtuFrqGF0wcJgcW4Mf+gkxuMT4ZrVNZ/Ty6gNMrUaVLnPSlCg6piKg ZVTLfv+4BtBOZQ6t8cNRCdgYvCl8CKLoA0Oc/cbCYC7oBB42ULImNBNc9j1SD/sHWEr2 eZugKR2IiKlTZfunaVxAN9r35KbvrgvHlTebqCiLPClyQbHepZhdwYVn7KpU3tM8nnR6 HkCT+qpYKdovl+26bByA9yXo0wl82B0gAzBfYl2ZSGDKvpaJQ4GJc1bPtpANevBAgaYw ZcHBwKC6vTI7nTADODpFkOujkHcjsiR0SfLVbMcp1y7qG65AQ9FIBUEKY8PNoYBmkU8N fPKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id n10si1427665edb.175.2019.10.30.05.27.32; Wed, 30 Oct 2019 05:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 906711C10E; Wed, 30 Oct 2019 13:26:54 +0100 (CET) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 226641C06A for ; Wed, 30 Oct 2019 13:26:14 +0100 (CET) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id D68C22007C1; Wed, 30 Oct 2019 13:26:13 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id DF2682007EA; Wed, 30 Oct 2019 13:26:10 +0100 (CET) Received: from GDB1.ap.freescale.net (gdb1.ap.freescale.net [10.232.132.179]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 3A63C40309; Wed, 30 Oct 2019 20:26:07 +0800 (SGT) From: Nipun Gupta To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@intel.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, Shreyansh Jain Date: Wed, 30 Oct 2019 17:39:55 +0530 Message-Id: <20191030120955.26904-10-nipun.gupta@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191030120955.26904-1-nipun.gupta@nxp.com> References: <20191011054657.21931-1-nipun.gupta@nxp.com> <20191030120955.26904-1-nipun.gupta@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH 9/9 v3] bus/fslmc: sanitize device name parsing for clarity X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Shreyansh Jain remove unnecessary dup and free Signed-off-by: Shreyansh Jain Reviewed-by: Nipun Gupta --- drivers/bus/fslmc/fslmc_bus.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 4116552c6..b3e964aa9 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -235,8 +235,9 @@ rte_fslmc_parse(const char *name, void *addr) { uint16_t dev_id; char *t_ptr; - char *sep = NULL; + const char *sep; uint8_t sep_exists = 0; + int ret = -1; DPAA2_BUS_DEBUG("Parsing dev=(%s)", name); @@ -266,10 +267,11 @@ rte_fslmc_parse(const char *name, void *addr) } else { DPAA2_BUS_DEBUG("Invalid device for matching (%s).", name); + ret = -EINVAL; goto err_out; } } else - sep = strdup(name); + sep = name; jump_out: /* Validate device name */ @@ -283,23 +285,23 @@ rte_fslmc_parse(const char *name, void *addr) strncmp("dpdmai", sep, 6) && strncmp("dpdmux", sep, 6)) { DPAA2_BUS_DEBUG("Unknown or unsupported device (%s)", sep); + ret = -EINVAL; goto err_out; } t_ptr = strchr(sep, '.'); if (!t_ptr || sscanf(t_ptr + 1, "%hu", &dev_id) != 1) { DPAA2_BUS_ERR("Missing device id in device name (%s)", sep); + ret = -EINVAL; goto err_out; } if (addr) strcpy(addr, sep); - return 0; + ret = 0; err_out: - if (!sep_exists && sep) - free(sep); - return -EINVAL; + return ret; } static int