From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 1B826B4C9 for ; Fri, 13 Feb 2015 16:03:23 +0100 (CET) Received: by mail-wg0-f52.google.com with SMTP id x12so7317532wgg.11 for ; Fri, 13 Feb 2015 07:03:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=XVFfZ75SF94EkKVww/eWzomBXShB7by0RJuSU1EkBNM=; b=GXNDyGCKbKQIPUlic9YCqyr1a9pMWyK7HHRketiQ+GsH4JC+LAoNg06sEsfWFw3xUr KyKFUxBQLOLz78NnjqMyjPUJQeo/ReEOSTDT0bgxLGiRPRVmJzhZQU/zcIFMYHWMwbBH OknClPtKK8+nGK9MKQSjWZslkAye12KaYb12dI1c/XqK7v4obUP4xYZNsdD0QZRlnT/F apRbTtfl/GFilT/pCOvRVC4hEcjkD5fgbydthiopBBYrXL3Dbx3oJOlk3KT3ETuU00ko D7uTa/YTlbeXpUVuHsFdDK8mnbnEZsasCOvJ8KczB6GNhhQGtHR5HvHdvAd5p00v0P3R rfPQ== X-Gm-Message-State: ALoCoQk6RR940bYdsl/PumHQoYamEpmi53JGOdSks0UCJcfzPTLGV1B8Wn3yGKcysLpkM4oSRzMH X-Received: by 10.194.158.39 with SMTP id wr7mr19565607wjb.118.1423839802962; Fri, 13 Feb 2015 07:03:22 -0800 (PST) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id e18sm10413605wjz.27.2015.02.13.07.03.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Feb 2015 07:03:22 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 13 Feb 2015 16:03:14 +0100 Message-Id: <1423839795-29450-3-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1423839795-29450-1-git-send-email-david.marchand@6wind.com> References: <1420635809-30976-1-git-send-email-david.marchand@6wind.com> <1423839795-29450-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 2/3] devargs: remove limit on parameters length X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Feb 2015 15:03:23 -0000 As far as I know, there is no reason why we should have a limit on the length of parameters that can be given for a device. Remove this limit by using dynamic allocations. Signed-off-by: David Marchand --- lib/librte_eal/common/eal_common_devargs.c | 26 +++++++++++++++++--------- lib/librte_eal/common/include/rte_devargs.h | 4 ++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 8c9b31a..3aace08 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -49,17 +49,10 @@ int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) { struct rte_devargs *devargs = NULL; - char buf[RTE_DEVARGS_LEN]; + char *buf = NULL; char *sep; int ret; - ret = snprintf(buf, sizeof(buf), "%s", devargs_str); - if (ret < 0 || ret >= (int)sizeof(buf)) { - RTE_LOG(ERR, EAL, "user device args too large: <%s>\n", - devargs_str); - goto fail; - } - /* use malloc instead of rte_malloc as it's called early at init */ devargs = malloc(sizeof(*devargs)); if (devargs == NULL) { @@ -69,11 +62,21 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) memset(devargs, 0, sizeof(*devargs)); devargs->type = devtype; + buf = strdup(devargs_str); + if (buf == NULL) { + RTE_LOG(ERR, EAL, "cannot allocate temp memory for devargs\n"); + goto fail; + } + /* set the first ',' to '\0' to split name and arguments */ sep = strchr(buf, ','); if (sep != NULL) { sep[0] = '\0'; - snprintf(devargs->args, sizeof(devargs->args), "%s", sep + 1); + devargs->args = strdup(sep + 1); + if (devargs->args == NULL) { + RTE_LOG(ERR, EAL, "cannot allocate for devargs args\n"); + goto fail; + } } switch (devargs->type) { @@ -97,10 +100,15 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) break; } + free(buf); TAILQ_INSERT_TAIL(&devargs_list, devargs, next); return 0; fail: + if (devargs->args) + free(devargs->args); + if (buf) + free(buf); if (devargs) free(devargs); return -1; diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 9f9c98f..996e180 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -88,8 +88,8 @@ struct rte_devargs { char drv_name[32]; } virtual; }; -#define RTE_DEVARGS_LEN 256 - char args[RTE_DEVARGS_LEN]; /**< Arguments string as given by user. */ + /** Arguments string as given by user. */ + char *args; }; /** user device double-linked queue type definition */ -- 1.7.10.4