From patchwork Mon May 29 16:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 100678 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp400047qge; Mon, 29 May 2017 09:01:00 -0700 (PDT) X-Received: by 10.157.11.110 with SMTP id p43mr6849903otd.215.1496073660309; Mon, 29 May 2017 09:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496073660; cv=none; d=google.com; s=arc-20160816; b=dbvtLCdxpy/+oo3F+7S1TG9gJNTSn7ssDDRtu0tkF/nWovVhvLvalxx9wHiB6EaKrL jY5PdaxkvLfmEfM99J+oXZDr+1s64diDiqEmE3crIQ+EsXedRmPHHs9BpgEKIbpvJ6mc 2q3YvR3DymitoCnGbOPLN5q0VASYOZWfQYhe+kByR5XaB82YEIMqLm4bNiIavFWmEPPl xMWyo/n+5sngBggVvVXzBbcZK+BSY+ksbG9MnMx8QDtugF/rhTAUk5p+HMEeacVZ5Jdd tflJl+mALiiLJmmO90EpU3IyXcYnBctCS7+EPNpQEneKKjM5VEOEviN6QzyGmhFMP9Qw OCYQ== 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:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=YyG90mk5tIgluXlQV2tYJ8TNCfafKI9PtC2DpDsgou0=; b=CygkRaKEwE636FJa/3jNc++IRKuZFgE67Jm+MJyQUFU6BI7zB1NwzIr41sGBWadBCh rFNkVeVUXu0w/7Z5hE68QLGBGqYl8RZ4dtvnb1qiIe0KAcgDztrEDCjFsMCcCPBi82+V xen0IvN09Iv2s7LYWCHQp9oHpuMejde+uek+8vAXqyCAO0POnt1xlsYQ5lwPFPkZwOI6 ccwqP9HezEOu2cxDtDYYPcZxZtgGT9vLTTNaycsixWjSenkqu/PPK0wEY1rTYEQSN4NW 3jEZU1nhUG0QwrVtPTvknocO8FhMluSnw9Qm2A9s7Ovkx2oDEFVwNVApK8w+uT9HYIFQ 9pmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s4si4188603otd.112.2017.05.29.09.01.00; Mon, 29 May 2017 09:01:00 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id CE6EE60ACB; Mon, 29 May 2017 16:00:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 7B87A60A57; Mon, 29 May 2017 16:00:27 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id F3494607B2; Mon, 29 May 2017 16:00:19 +0000 (UTC) Received: from forward4m.cmail.yandex.net (forward4m.cmail.yandex.net [5.255.216.22]) by lists.linaro.org (Postfix) with ESMTPS id EDAFF607AD for ; Mon, 29 May 2017 16:00:17 +0000 (UTC) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [37.140.190.27]) by forward4m.cmail.yandex.net (Yandex) with ESMTP id 6DCA020DA9 for ; Mon, 29 May 2017 19:00:16 +0300 (MSK) Received: from smtp2o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2o.mail.yandex.net (Yandex) with ESMTP id 101075081189 for ; Mon, 29 May 2017 19:00:15 +0300 (MSK) Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Drc3SPYrvM-0EdCuTZs; Mon, 29 May 2017 19:00:14 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Mon, 29 May 2017 19:00:08 +0300 Message-Id: <1496073608-17292-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1496073608-17292-1-git-send-email-odpbot@yandex.ru> References: <1496073608-17292-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 37 Subject: [lng-odp] [PATCH API-NEXT v3 1/1] api: crypto: make odp_crypto_session_create return odp_crypto_session_t X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Currently odp_crypto_session_create() (unlike other creation functions) returns int result with session being returned through pointer argument. Instead it is simpler to directly return a session (or ODP_CRYPTO_SESSION_INVALID in case of an error). Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 37 (lumag:crypto-create-ret) ** https://github.com/Linaro/odp/pull/37 ** Patch: https://github.com/Linaro/odp/pull/37.patch ** Base sha: 552817483e9d4b6a84d49960920f1de50029f111 ** Merge commit sha: ce4931bac5b0c0cbf78cd588754e558a6145fea0 **/ example/ipsec/odp_ipsec_cache.c | 4 +- include/odp/api/spec/crypto.h | 12 ++-- platform/linux-generic/odp_crypto.c | 14 ++--- test/common_plat/performance/odp_crypto.c | 68 +++++++++++----------- .../validation/api/crypto/odp_crypto_test_inp.c | 6 +- 5 files changed, 50 insertions(+), 54 deletions(-) diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c index b2a91c24..15617bc7 100644 --- a/example/ipsec/odp_ipsec_cache.c +++ b/example/ipsec/odp_ipsec_cache.c @@ -114,8 +114,8 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, return -1; } - /* Synchronous session create for now */ - if (odp_crypto_session_create(¶ms, &session, &ses_create_rc)) + session = odp_crypto_session_create(¶ms, &ses_create_rc); + if (ODP_CRYPTO_SESSION_INVALID == session) return -1; if (ODP_CRYPTO_SES_CREATE_ERR_NONE != ses_create_rc) return -1; diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index c47d3149..493e17f7 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -585,15 +585,15 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, * default values. * * @param param Session parameters - * @param session Created session else ODP_CRYPTO_SESSION_INVALID * @param status Failure code if unsuccessful * - * @retval 0 on success - * @retval <0 on failure + * @retval created session on success + * @retval ODP_CRYPTO_SESSION_INVALID on failure */ -int odp_crypto_session_create(odp_crypto_session_param_t *param, - odp_crypto_session_t *session, - odp_crypto_ses_create_err_t *status); +odp_crypto_session_t odp_crypto_session_create(odp_crypto_session_param_t + *param, + odp_crypto_ses_create_err_t + *status); /** * Crypto session destroy diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index a993542f..11d3af3a 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -656,9 +656,8 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, return num; } -int +odp_crypto_session_t odp_crypto_session_create(odp_crypto_session_param_t *param, - odp_crypto_session_t *session_out, odp_crypto_ses_create_err_t *status) { int rc; @@ -672,7 +671,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, session = alloc_session(); if (NULL == session) { *status = ODP_CRYPTO_SES_CREATE_ERR_ENOMEM; - return -1; + return ODP_CRYPTO_SESSION_INVALID; } /* Copy parameters */ @@ -683,7 +682,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (session->p.iv.length > MAX_IV_LEN) { ODP_DBG("Maximum IV length exceeded\n"); free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } memcpy(session->cipher.iv_data, session->p.iv.data, @@ -734,7 +733,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (rc) { *status = ODP_CRYPTO_SES_CREATE_ERR_INV_CIPHER; free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } aes_gcm = 0; @@ -781,12 +780,11 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (rc) { *status = ODP_CRYPTO_SES_CREATE_ERR_INV_AUTH; free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } /* We're happy */ - *session_out = (intptr_t)session; - return 0; + return (odp_crypto_session_t)(intptr_t)session; } int odp_crypto_session_destroy(odp_crypto_session_t session) diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c index b3857973..95cc141c 100644 --- a/test/common_plat/performance/odp_crypto.c +++ b/test/common_plat/performance/odp_crypto.c @@ -415,13 +415,13 @@ print_mem(const char *msg, /** * Create ODP crypto session for given config. */ -static int -create_session_from_config(odp_crypto_session_t *session, - crypto_alg_config_t *config, +static odp_crypto_session_t +create_session_from_config(crypto_alg_config_t *config, crypto_args_t *cargs) { odp_crypto_session_param_t params; odp_crypto_ses_create_err_t ses_create_rc; + odp_crypto_session_t session; odp_pool_t pkt_pool; odp_queue_t out_queue; @@ -434,7 +434,7 @@ create_session_from_config(odp_crypto_session_t *session, pkt_pool = odp_pool_lookup("packet_pool"); if (pkt_pool == ODP_POOL_INVALID) { app_err("packet_pool pool not found\n"); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } params.output_pool = pkt_pool; @@ -442,20 +442,21 @@ create_session_from_config(odp_crypto_session_t *session, out_queue = odp_queue_lookup("crypto-out"); if (out_queue == ODP_QUEUE_INVALID) { app_err("crypto-out queue not found\n"); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } params.compl_queue = out_queue; } else { params.compl_queue = ODP_QUEUE_INVALID; } - if (odp_crypto_session_create(¶ms, session, - &ses_create_rc)) { + + session = odp_crypto_session_create(¶ms, + &ses_create_rc); + + if (session == ODP_CRYPTO_SESSION_INVALID) app_err("crypto session create failed.\n"); - return -1; - } - return 0; + return session; } /** @@ -664,35 +665,34 @@ run_measure_one_config(crypto_args_t *cargs, odp_crypto_session_t session; int rc = 0; - if (create_session_from_config(&session, config, cargs)) - rc = -1; - - if (!rc) { - if (cargs->payload_length) { - rc = run_measure_one(cargs, config, &session, - cargs->payload_length, &result); - if (!rc) { - print_result_header(); - print_result(cargs, cargs->payload_length, - config, &result); - } - } else { - unsigned i; + session = create_session_from_config(config, cargs); + if (session == ODP_CRYPTO_SESSION_INVALID) + return -1; + if (cargs->payload_length) { + rc = run_measure_one(cargs, config, &session, + cargs->payload_length, &result); + if (!rc) { print_result_header(); - for (i = 0; i < num_payloads; i++) { - rc = run_measure_one(cargs, config, &session, - payloads[i], &result); - if (rc) - break; - print_result(cargs, payloads[i], - config, &result); - } + print_result(cargs, cargs->payload_length, + config, &result); + } + } else { + unsigned i; + + print_result_header(); + for (i = 0; i < num_payloads; i++) { + rc = run_measure_one(cargs, config, &session, + payloads[i], &result); + if (rc) + break; + print_result(cargs, payloads[i], + config, &result); } } - if (session != ODP_CRYPTO_SESSION_INVALID) - odp_crypto_session_destroy(session); + odp_crypto_session_destroy(session); + return rc; } diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index bfc9da3c..c82f7212 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -202,11 +202,9 @@ static void alg_test(odp_crypto_op_t op, ses_params.iv = ses_iv; ses_params.auth_key = auth_key; - rc = odp_crypto_session_create(&ses_params, &session, &status); - CU_ASSERT_FATAL(!rc); + session = odp_crypto_session_create(&ses_params, &status); + CU_ASSERT_FATAL(session != ODP_CRYPTO_SESSION_INVALID); CU_ASSERT(status == ODP_CRYPTO_SES_CREATE_ERR_NONE); - CU_ASSERT(odp_crypto_session_to_u64(session) != - odp_crypto_session_to_u64(ODP_CRYPTO_SESSION_INVALID)); /* Prepare input data */ odp_packet_t pkt = odp_packet_alloc(suite_context.pool,