From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 8F36E7CA3 for ; Fri, 14 Jul 2017 23:12:39 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id 15so936564wmm.3 for ; Fri, 14 Jul 2017 14:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=BPtpaRJBaDNW3Qvdn2cTz9TFaTidAlc6QsBD09LxjIo=; b=mv2XsO97GZK/JXWCTGNJF3N15rOY6ajMoIB5iFy5FH7Nt6tBuHVU6RD6zQq3wwdba/ AMirqVg20tV7Iqd98E2NwBkJPFhSAwNJSry2CgtiR6dXOQwONH7SK8E8yahLnk/dNVyD xKKWKrc9JLdkpGRUahJgEZQUCdt8sRNU4hGPlKAfDr4FwjNL6osbu6dhUG4LYILy/0vd HUCdO8A7WF2NUhl54FcXkB9Spwhs/Tuinb/ZINehiwDbuhMoqie9txYp2rVJNgc+yHtH N6wTI47oYbLRck6/u4iOKBtePNJmv0eKjkROp0aEF463RZ629HtI658JMANf7+zS9rkJ WGWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=BPtpaRJBaDNW3Qvdn2cTz9TFaTidAlc6QsBD09LxjIo=; b=DgfGdtU/SY6KGABPYTfckPym4SfKFiuxCJMRFsFdQM5f94fXek6jQa69uWeE9GUIfs ObG/8JUVRec3SnhRc/op1dBvL/lryYpua2K1dps5o/PlURMHtror6oARFF0+V5J1zCgp d1IeNTeaIok9Y4smFKwxCdzs+u5rsmgU8aq9gSb2ECWO1i/Z5VnFtIWswDYjqk7pwG+h KgQuycKLydUVr13wQ3v8CkM20TJPMSkqadRj+/CaM5eyS15BpxQ4RfjPl7aGIQavqfqc kzd1x1PMbCJXdJrGLYY41A6MChkyDjB47QK6qQVKoaxoNQ3c+2cHfuOyr8lS3CW7VA9n /rQQ== X-Gm-Message-State: AIVw11046cJyLr1QMLlTobqlCClEWej4FPWC1OS/5x9NJy+BLGkaX0TS zn9Sp9wSeEOmtP1Y X-Received: by 10.80.220.138 with SMTP id r10mr8132751edk.91.1500066759081; Fri, 14 Jul 2017 14:12:39 -0700 (PDT) Received: from localhost.localdomain ([37.228.147.16]) by smtp.gmail.com with ESMTPSA id c11sm4892223eda.0.2017.07.14.14.12.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:12:38 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Date: Fri, 14 Jul 2017 17:12:06 -0400 Message-Id: <20170714211213.34436-9-jblunck@infradead.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170714211213.34436-1-jblunck@infradead.org> References: <20170711232512.54641-1-jblunck@infradead.org> <20170714211213.34436-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v2 08/15] devargs: use existing functions in rte_eal_devargs_parse() 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: , X-List-Received-Date: Fri, 14 Jul 2017 21:12:39 -0000 This fixes the newly introduces rte_eal_devargs_parse() to make use of: - snprintf() instead of open coding a while() loop - rte_eal_parse_devargs_str() instead of duplicating parsing code - RTE_LOG() instead of direct output to stderr Signed-off-by: Jan Blunck --- lib/librte_eal/common/eal_common_devargs.c | 57 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 205fabb95..b5273287e 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -87,54 +87,53 @@ int rte_eal_devargs_parse(const char *dev, struct rte_devargs *da) { struct rte_bus *bus = NULL; - const char *devname; - const size_t maxlen = sizeof(da->name); - size_t i; + char *devname = NULL, *drvargs = NULL; + int ret; if (dev == NULL || da == NULL) return -EINVAL; /* Retrieve eventual bus info */ do { - devname = dev; bus = rte_bus_find(bus, bus_name_cmp, dev); if (bus == NULL) break; - devname = dev + strlen(bus->name) + 1; - if (rte_bus_find_by_device_name(devname) == bus) + dev += strlen(bus->name) + 1; + if (rte_bus_find_by_device_name(dev) == bus) break; } while (1); + + ret = rte_eal_parse_devargs_str(dev, &devname, &drvargs); + if (ret != 0) + return ret; + /* Store device name */ - i = 0; - while (devname[i] != '\0' && devname[i] != ',') { - da->name[i] = devname[i]; - i++; - if (i == maxlen) { - fprintf(stderr, "WARNING: Parsing \"%s\": device name should be shorter than %zu\n", - dev, maxlen); - da->name[i - 1] = '\0'; - return -EINVAL; - } + ret = snprintf(da->name, sizeof(da->name), "%s", devname); + if (ret < 0 || ret >= (int)sizeof(da->name)) { + RTE_LOG(ERR, EAL, "Invalid device name: \"%s\"\n", devname); + ret = -EINVAL; + goto fail; } - da->name[i] = '\0'; + + /* Store drivers arguments */ + da->args = drvargs; + drvargs = NULL; + if (bus == NULL) { bus = rte_bus_find_by_device_name(da->name); if (bus == NULL) { - fprintf(stderr, "ERROR: failed to parse device \"%s\"\n", + RTE_LOG(ERR, EAL, "Failed to parse device: \"%s\"\n", da->name); - return -EFAULT; + ret = -EFAULT; + goto fail; } } da->bus = bus; - /* Parse eventual device arguments */ - if (devname[i] == ',') - da->args = strdup(&devname[i + 1]); - else - da->args = strdup(""); - if (da->args == NULL) { - fprintf(stderr, "ERROR: not enough memory to parse arguments\n"); - return -ENOMEM; - } - return 0; + ret = 0; + +fail: + free(devname); + free(drvargs); + return ret; } static const struct rte_bus_conf BUS_CONF_WHITELIST = { -- 2.13.2