From patchwork Tue Oct 20 20:21:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoni Fogel X-Patchwork-Id: 7789 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 1FE4A8E94; Tue, 20 Oct 2015 22:45:09 +0200 (CEST) Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by dpdk.org (Postfix) with ESMTP id 89D778E93 for ; Tue, 20 Oct 2015 22:45:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1445373907; x=1476909907; h=from:to:subject:date:message-id:mime-version; bh=rmVXYhTtT7OfzJR34Qivs5WyBSd/Jp2bA7syyA+pnIA=; b=gP6LdaECU1aCkqbKtfcFxfhnr1x/q772Sz34lCk8j6DDQtimZZDhzSHh Ai9xRX2m4d2YJ+trA/Wh+ioGB9p4K4TjmBNJ+tmOCu8LKy5WBqL1KULo4 aullXwMGr6rtx5Uw+CeegVtHJ965WDxf9XxESKGg+7cf5uTd4mqdJgCWP 4=; X-IronPort-AV: E=Sophos;i="5.17,708,1437436800"; d="scan'208";a="344372769" Received: from sea3-co-svc-lb3-vlan2.amazon.com (HELO email-inbound-relay-60009.pdx1.amazon.com) ([172.18.12.82]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Oct 2015 20:21:52 +0000 Received: from ex10-hub-7002.ant.amazon.com (pdx1-ws-svc-lb16-vlan2.amazon.com [10.239.138.210]) by email-inbound-relay-60009.pdx1.amazon.com (8.14.7/8.14.7) with ESMTP id t9KKLoVD010333 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Tue, 20 Oct 2015 20:21:52 GMT Received: from EX13D11UWB003.ant.amazon.com (10.43.161.206) by ex10-hub-7002.ant.amazon.com (10.43.110.153) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 20 Oct 2015 13:21:42 -0700 Received: from uf8bc12800b5c53f661e4.amazon.com (10.43.162.161) by EX13D11UWB003.ant.amazon.com (10.43.161.206) with Microsoft SMTP Server (TLS) id 15.0.1076.9; Tue, 20 Oct 2015 20:21:40 +0000 From: Yoni Fogel To: Date: Tue, 20 Oct 2015 13:21:37 -0700 Message-ID: <1445372497-817-1-git-send-email-yrobot@amazon.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 X-Originating-IP: [10.43.162.161] X-ClientProxiedBy: EX13D10UWB001.ant.amazon.com (10.43.161.111) To EX13D11UWB003.ant.amazon.com (10.43.161.206) Precedence: Bulk Subject: [dpdk-dev] [PATCH] lib: rte_*_create gives NULL/EEXIST on duped name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Also fixed a bug in many of them where if the rte_malloc of the TAILQ fails, then we return a pointer to some arbitrary existing struct. Signed-off-by: Yoni Fogel --- lib/librte_acl/rte_acl.c | 53 +++++++++++++++++++++------------------ lib/librte_hash/rte_cuckoo_hash.c | 6 +++-- lib/librte_hash/rte_fbk_hash.c | 5 +++- lib/librte_lpm/rte_lpm.c | 5 +++- lib/librte_lpm/rte_lpm6.c | 5 +++- 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c index d60219f..f591556 100644 --- a/lib/librte_acl/rte_acl.c +++ b/lib/librte_acl/rte_acl.c @@ -213,37 +213,40 @@ rte_acl_create(const struct rte_acl_param *param) break; } + ctx = NULL; + if (te != NULL) { + rte_errno = EEXIST; + goto exit; + } + /* if ACL with such name doesn't exist, then create a new one. */ - if (te == NULL) { - ctx = NULL; - te = rte_zmalloc("ACL_TAILQ_ENTRY", sizeof(*te), 0); + te = rte_zmalloc("ACL_TAILQ_ENTRY", sizeof(*te), 0); - if (te == NULL) { - RTE_LOG(ERR, ACL, "Cannot allocate tailq entry!\n"); - goto exit; - } + if (te == NULL) { + RTE_LOG(ERR, ACL, "Cannot allocate tailq entry!\n"); + goto exit; + } - ctx = rte_zmalloc_socket(name, sz, RTE_CACHE_LINE_SIZE, param->socket_id); + ctx = rte_zmalloc_socket(name, sz, RTE_CACHE_LINE_SIZE, param->socket_id); - if (ctx == NULL) { - RTE_LOG(ERR, ACL, - "allocation of %zu bytes on socket %d for %s failed\n", - sz, param->socket_id, name); - rte_free(te); - goto exit; - } - /* init new allocated context. */ - ctx->rules = ctx + 1; - ctx->max_rules = param->max_rule_num; - ctx->rule_sz = param->rule_size; - ctx->socket_id = param->socket_id; - ctx->alg = rte_acl_default_classify; - snprintf(ctx->name, sizeof(ctx->name), "%s", param->name); + if (ctx == NULL) { + RTE_LOG(ERR, ACL, + "allocation of %zu bytes on socket %d for %s failed\n", + sz, param->socket_id, name); + rte_free(te); + goto exit; + } + /* init new allocated context. */ + ctx->rules = ctx + 1; + ctx->max_rules = param->max_rule_num; + ctx->rule_sz = param->rule_size; + ctx->socket_id = param->socket_id; + ctx->alg = rte_acl_default_classify; + snprintf(ctx->name, sizeof(ctx->name), "%s", param->name); - te->data = (void *) ctx; + te->data = (void *) ctx; - TAILQ_INSERT_TAIL(acl_list, te, next); - } + TAILQ_INSERT_TAIL(acl_list, te, next); exit: rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 7019763..fe5a79e 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -206,8 +206,10 @@ rte_hash_create(const struct rte_hash_parameters *params) /* Guarantee there's no existing */ h = rte_hash_find_existing(params->name); - if (h != NULL) - return h; + if (h != NULL) { + rte_errno = EEXIST; + return NULL; + } te = rte_zmalloc("HASH_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 8752a47..55c9f35 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -140,8 +140,11 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0) break; } - if (te != NULL) + ht = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } te = rte_zmalloc("FBK_HASH_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index 163ba3c..ea3cd44 100644 --- a/lib/librte_lpm/rte_lpm.c +++ b/lib/librte_lpm/rte_lpm.c @@ -181,8 +181,11 @@ rte_lpm_create(const char *name, int socket_id, int max_rules, if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0) break; } - if (te != NULL) + lpm = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } /* allocate tailq entry */ te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0); diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c index 6c2b293..ff0bd76 100644 --- a/lib/librte_lpm/rte_lpm6.c +++ b/lib/librte_lpm/rte_lpm6.c @@ -182,8 +182,11 @@ rte_lpm6_create(const char *name, int socket_id, if (strncmp(name, lpm->name, RTE_LPM6_NAMESIZE) == 0) break; } - if (te != NULL) + lpm = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } /* allocate tailq entry */ te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0);