From patchwork Tue Oct 3 10:42:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 114692 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1725449qgn; Tue, 3 Oct 2017 03:48:26 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDb3GSC/QbHEuzknMTAywvzX6rc8kJHIlSru+q5g3XDEcGOtmQeAj4U6MNBhjnXaFIVlrqE X-Received: by 10.98.103.143 with SMTP id t15mr3752453pfj.270.1507027706323; Tue, 03 Oct 2017 03:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507027706; cv=none; d=google.com; s=arc-20160816; b=qLn9C9RXKUXKjIMJxopYRh+pTTR9nPOlWyQTXTbZ83+wPh0kD/SN+cEqVKCjLqpKWt 4kPZbpBEZ8fvT5G5QOChDHWfaY22NnDeSHW4iMsUgzlmn/DzAlJWbGsxcicBpRyv3RI/ fJ8qVk/weEp9ZwriAiO6uqt9LhvYmIu6Fc0kkv+mKpPImujYym72eyC1JFVdhQFThRPq LYIU5n04Rh9v19wRG/kdsZoRM7vha8QQcVCfEpVyA4H+jeQ9tr5a+/CKeXMTk5EMYRNx JqRDdnsw8V6T80VtgipyDf9JrC352OnDZog0wvz9tK5KsxOwG9fEttZODyK9N+QCxWzP PK1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=yXvH5bBN6WpC1WrO0CEaUNPOmg/K2AgpFN2bbvfF2ic=; b=WK6rnqPIEGZI54HbCk9PWelZzLO87P9BHr8RQ1emp0rVuTJTiC17479mrALeuecEci cYs0sqmPcFofSsKk6ayrz5uQVzkIPN408XNf7E5hHZtA6vaPIxdkl4VVCyDV+R9q1DO+ Jt97QX6Rb8TfckBKEjj7O+59w1djaT/LbDXqtqfVUBJm7BTrqFb6g7zan3U+OkFuMaEn tscjpXKhReaeFsxvQUKrrQdScv5WHyIjKoSWTPBN0EU0OLEBhaqAyRM2X4s4QdtEIBDy sNGXJZm6RlNfVILrwanG57KCI0dKEMDj39GWaep49Ca2IzwuC8zDqK+GNdDzVauaFBXR t/4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r84si969050pfi.228.2017.10.03.03.48.26; Tue, 03 Oct 2017 03:48:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751933AbdJCKsX (ORCPT + 26 others); Tue, 3 Oct 2017 06:48:23 -0400 Received: from foss.arm.com ([217.140.101.70]:46802 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdJCKsM (ORCPT ); Tue, 3 Oct 2017 06:48:12 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 149D580D; Tue, 3 Oct 2017 03:48:12 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A5FEB3F578; Tue, 3 Oct 2017 03:48:09 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] staging: ccree: simplify OOM handling Date: Tue, 3 Oct 2017 11:42:17 +0100 Message-Id: <1507027339-23824-5-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507027339-23824-1-git-send-email-gilad@benyossef.com> References: <1507027339-23824-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify handling of memory allocation failures and remove redundant log messages Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_cipher.c | 11 ++++------ drivers/staging/ccree/ssi_driver.c | 1 - drivers/staging/ccree/ssi_hash.c | 42 +++++++++++++----------------------- drivers/staging/ccree/ssi_ivgen.c | 9 +++----- drivers/staging/ccree/ssi_sram_mgr.c | 23 ++++---------------- 5 files changed, 26 insertions(+), 60 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index d70d86a..78706f5 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -194,10 +194,9 @@ static int ssi_blkcipher_init(struct crypto_tfm *tfm) /* Allocate key buffer, cache line aligned */ ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL | GFP_DMA); - if (!ctx_p->user.key) { - dev_dbg(dev, "Allocating key buffer in context failed\n"); - rc = -ENOMEM; - } + if (!ctx_p->user.key) + return -ENOMEM; + dev_dbg(dev, "Allocated key buffer in context. key=@%p\n", ctx_p->user.key); @@ -1245,10 +1244,8 @@ struct ssi_crypto_alg *ssi_ablkcipher_create_alg(struct ssi_alg_template struct crypto_alg *alg; t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); - if (!t_alg) { - dev_dbg(dev, "failed to allocate t_alg\n"); + if (!t_alg) return ERR_PTR(-ENOMEM); - } alg = &t_alg->crypto_alg; diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index c4b608b..795a087 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -212,7 +212,6 @@ static int init_cc_resources(struct platform_device *plat_dev) new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL); if (!new_drvdata) { - dev_dbg(dev, "Failed to allocate drvdata"); rc = -ENOMEM; goto post_drvdata_err; } diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c index a27c988..d79090e 100644 --- a/drivers/staging/ccree/ssi_hash.c +++ b/drivers/staging/ccree/ssi_hash.c @@ -157,34 +157,28 @@ static int ssi_hash_map_request(struct device *dev, int rc = -ENOMEM; state->buff0 = kzalloc(SSI_MAX_HASH_BLCK_SIZE, GFP_KERNEL | GFP_DMA); - if (!state->buff0) { - dev_err(dev, "Allocating buff0 in context failed\n"); + if (!state->buff0) goto fail0; - } + state->buff1 = kzalloc(SSI_MAX_HASH_BLCK_SIZE, GFP_KERNEL | GFP_DMA); - if (!state->buff1) { - dev_err(dev, "Allocating buff1 in context failed\n"); + if (!state->buff1) goto fail_buff0; - } + state->digest_result_buff = kzalloc(SSI_MAX_HASH_DIGEST_SIZE, GFP_KERNEL | GFP_DMA); - if (!state->digest_result_buff) { - dev_err(dev, "Allocating digest_result_buff in context failed\n"); + if (!state->digest_result_buff) goto fail_buff1; - } + state->digest_buff = kzalloc(ctx->inter_digestsize, GFP_KERNEL | GFP_DMA); - if (!state->digest_buff) { - dev_err(dev, "Allocating digest-buffer in context failed\n"); + if (!state->digest_buff) goto fail_digest_result_buff; - } dev_dbg(dev, "Allocated digest-buffer in context ctx->digest_buff=@%p\n", state->digest_buff); if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC) { state->digest_bytes_len = kzalloc(HASH_LEN_SIZE, GFP_KERNEL | GFP_DMA); - if (!state->digest_bytes_len) { - dev_err(dev, "Allocating digest-bytes-len in context failed\n"); + if (!state->digest_bytes_len) goto fail1; - } + dev_dbg(dev, "Allocated digest-bytes-len in context state->>digest_bytes_len=@%p\n", state->digest_bytes_len); } else { @@ -192,10 +186,9 @@ static int ssi_hash_map_request(struct device *dev, } state->opad_digest_buff = kzalloc(ctx->inter_digestsize, GFP_KERNEL | GFP_DMA); - if (!state->opad_digest_buff) { - dev_err(dev, "Allocating opad-digest-buffer in context failed\n"); + if (!state->opad_digest_buff) goto fail2; - } + dev_dbg(dev, "Allocated opad-digest-buffer in context state->digest_bytes_len=@%p\n", state->opad_digest_buff); @@ -2057,10 +2050,9 @@ ssi_hash_create_alg(struct ssi_hash_template *template, struct device *dev, struct ahash_alg *halg; t_crypto_alg = kzalloc(sizeof(*t_crypto_alg), GFP_KERNEL); - if (!t_crypto_alg) { - dev_dbg(dev, "failed to allocate t_crypto_alg\n"); + if (!t_crypto_alg) return ERR_PTR(-ENOMEM); - } + t_crypto_alg->ahash_alg = template->template_ahash; halg = &t_crypto_alg->ahash_alg; @@ -2225,12 +2217,8 @@ int ssi_hash_alloc(struct ssi_drvdata *drvdata) int alg; hash_handle = kzalloc(sizeof(*hash_handle), GFP_KERNEL); - if (!hash_handle) { - dev_err(dev, "kzalloc failed to allocate %zu B\n", - sizeof(*hash_handle)); - rc = -ENOMEM; - goto fail; - } + if (!hash_handle) + return -ENOMEM; INIT_LIST_HEAD(&hash_handle->hash_list); drvdata->hash_handle = hash_handle; diff --git a/drivers/staging/ccree/ssi_ivgen.c b/drivers/staging/ccree/ssi_ivgen.c index 2982c8b..3f082f4 100644 --- a/drivers/staging/ccree/ssi_ivgen.c +++ b/drivers/staging/ccree/ssi_ivgen.c @@ -193,12 +193,9 @@ int ssi_ivgen_init(struct ssi_drvdata *drvdata) /* Allocate "this" context */ drvdata->ivgen_handle = kzalloc(sizeof(*drvdata->ivgen_handle), GFP_KERNEL); - if (!drvdata->ivgen_handle) { - dev_err(device, "Not enough memory to allocate IVGEN context (%zu B)\n", - sizeof(*drvdata->ivgen_handle)); - rc = -ENOMEM; - goto out; - } + if (!drvdata->ivgen_handle) + return -ENOMEM; + ivgen_ctx = drvdata->ivgen_handle; /* Allocate pool's header for intial enc. key/IV */ diff --git a/drivers/staging/ccree/ssi_sram_mgr.c b/drivers/staging/ccree/ssi_sram_mgr.c index 25dfd7e..07260d1 100644 --- a/drivers/staging/ccree/ssi_sram_mgr.c +++ b/drivers/staging/ccree/ssi_sram_mgr.c @@ -50,29 +50,14 @@ void ssi_sram_mgr_fini(struct ssi_drvdata *drvdata) */ int ssi_sram_mgr_init(struct ssi_drvdata *drvdata) { - struct ssi_sram_mgr_ctx *smgr_ctx; - struct device *dev = drvdata_to_dev(drvdata); - int rc; - /* Allocate "this" context */ - drvdata->sram_mgr_handle = kzalloc( - sizeof(struct ssi_sram_mgr_ctx), GFP_KERNEL); - if (!drvdata->sram_mgr_handle) { - dev_err(dev, "Not enough memory to allocate SRAM_MGR ctx (%zu)\n", - sizeof(struct ssi_sram_mgr_ctx)); - rc = -ENOMEM; - goto out; - } - smgr_ctx = drvdata->sram_mgr_handle; + drvdata->sram_mgr_handle = kzalloc(sizeof(struct ssi_sram_mgr_ctx), + GFP_KERNEL); - /* Pool starts at start of SRAM */ - smgr_ctx->sram_free_offset = 0; + if (!drvdata->sram_mgr_handle) + return -ENOMEM; return 0; - -out: - ssi_sram_mgr_fini(drvdata); - return rc; } /*!