From patchwork Tue Nov 5 14:23:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 178528 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp847433ilf; Tue, 5 Nov 2019 06:41:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyFnwp/6Ocn/idcZ6Hj68FlkAwD9IiaeawMEH7IHReapnORUWctaqg1GUiGHbXOlmhaZEvM X-Received: by 2002:a17:906:2a89:: with SMTP id l9mr29849018eje.329.1572964872057; Tue, 05 Nov 2019 06:41:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572964872; cv=none; d=google.com; s=arc-20160816; b=IyrLirOefzqtwZjztkGo3S1TbRjahe9IyFri4uZzFibN38AUHpVLd7vlNurYzT1Db0 VPS7n2s0Zx3iyUa94EegMDxwD5tBecXg1YLq/XXwtQi8TkWXqi4rBCs3NTJ6L44ggO8Z OX9E89J70tCIOrOTcOTd4egiuvMzV3u+Haa3BWbdq4ge1YtGjxVACffWLw/lNy4+L1cD H02cwUgBs/ZGm0PocNV5W12z0KD4kx3wIW0Gb2MCD+UgVY0sZtrrI4XPUS5Q2yLAa5CB jR6qPrid/2NdIzhCa5g2ZXk0mZr6TqlQm+42SFObwDeoeXKqwOWtaOyu7E/PbnqhhRl2 6UcA== 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=euE2jjThgMxvidi6AlV4r2VU/TAlu3O8v2LCUEU8ph0=; b=Zr+geATvAHNDlFvggJSP0uih4Lx7xlbMRnfRsIzhb+in2Saxv5j/9cHjVrogZoDIIu Rk1/oTaXIPp2+md+PgJ49reU+cMV3dCkU8UPgK0SKFNRTPepQ1iX0QiElIBxT7+AVuWL Mt8FiSunLjyqYBTxUs7Bn+4z4zQz0nrUMpmBnD+gdshR7XUeyJ08uroJTscfKgDtLeSi CWPrmXSy1CfL6J7FfIBk1XZs2HOnPsnOxdkUMPfM7CJZEZ6WinHDQYc/U8XOjfDcQw4V xQI2qmMe1p8jlkjcGNj7o9nL28cFl+2WYVBXJTVuEi3tqRXlPlPTO1ancMRDGwgXdfZJ +1qw== 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 d7si10458166eda.429.2019.11.05.06.41.11; Tue, 05 Nov 2019 06:41:12 -0800 (PST) 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 BA8AC1BF69; Tue, 5 Nov 2019 15:39:59 +0100 (CET) Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by dpdk.org (Postfix) with ESMTP id B99BF1BF41 for ; Tue, 5 Nov 2019 15:39:53 +0100 (CET) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 9F0031A00C5; Tue, 5 Nov 2019 15:39:53 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id AA3911A056E; Tue, 5 Nov 2019 15:39:50 +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 1C0D44031F; Tue, 5 Nov 2019 22:39:45 +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: Tue, 5 Nov 2019 19:53:21 +0530 Message-Id: <20191105142321.7478-10-nipun.gupta@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191105142321.7478-1-nipun.gupta@nxp.com> References: <20191011054657.21931-1-nipun.gupta@nxp.com> <20191105142321.7478-1-nipun.gupta@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH 9/9 v4] 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" remove unnecessary dup and free Signed-off-by: Shreyansh Jain Reviewed-by: Nipun Gupta --- drivers/bus/fslmc/fslmc_bus.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 9caf5b6b9..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,26 +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) { + if (addr) strcpy(addr, sep); - if (!sep_exists && sep) - free(sep); - return 0; - } + ret = 0; err_out: - if (!sep_exists && sep) - free(sep); - return -EINVAL; + return ret; } static int