From patchwork Thu Sep 15 14:45:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9333859 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86CB16077A for ; Thu, 15 Sep 2016 14:46:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A40828DB5 for ; Thu, 15 Sep 2016 14:46:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EC19298C5; Thu, 15 Sep 2016 14:46:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1704128DB5 for ; Thu, 15 Sep 2016 14:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751681AbcIOOp4 (ORCPT ); Thu, 15 Sep 2016 10:45:56 -0400 Received: from mout.web.de ([217.72.192.78]:63683 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750731AbcIOOpi (ORCPT ); Thu, 15 Sep 2016 10:45:38 -0400 Received: from [192.168.1.2] ([77.181.210.244]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0LzbDC-1axTwp3QqA-014j5B; Thu, 15 Sep 2016 16:45:29 +0200 Subject: [PATCH 6/6] crypto-caamhash: Move common error handling code in two functions To: linux-crypto@vger.kernel.org, "David S. Miller" , Herbert Xu , Labbe Corentin , Russell King References: <566ABCD9.1060404@users.sourceforge.net> <970e9e1b-c1dc-eb28-b380-92c15e9b1961@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: Date: Thu, 15 Sep 2016 16:45:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <970e9e1b-c1dc-eb28-b380-92c15e9b1961@users.sourceforge.net> X-Provags-ID: V03:K0:Jd8VwTNZR1iQ+1a8UqlkGXJswA85lLUvOIRj3Kc/xAXKvTopCbZ dBkpiO1YbyQvJGB2VHlf8+GmPOib1xddDKa7kBteuoAFoXEpv9F0x36fq3njz6DPHfmrgbu RMYJ+ZsjZ7JqG5x9n3LsHywCr4hgSb75xu02JAAx04ZVoi78BsymtV+YwIkgOvMR7vICy2P 8Qvv1j8HDiy0VQCLH9ohQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:8H1Urx3uPQY=:XHLw7YH1TM+rzTv0J75Dfh bm+teArt+XvrZpW/JcAH3WGThVH2l3VZWyi0OTuQBUse0neqDDT7SA/8nVHzyPpXLiqpSMopj Ok0vEC8oQIOgQHiDe0YxXiH+1JsheWuEZ8uxIYhwOfAtQY5RY+5EyuT5Y65tO4jOvXAT/hTac Kn8NTvTK24pB2POPbz6Vg0DB9o5p25sspzehH+LCKS6tPJjbIhCPINhNSv6Jpc+Kssnxc+pRG Bm6OKJ3NwbBHoX+CffcUHg/PIYZZJ+XAfbVgGhrjSiIMtJfWtEsDnrx9NQzFzvW/1xvRD39rq 8ls6Tf7dYDREE7lE2ur8lEHgXkF42A2JKNJbKgbJtmIXBjgYSalKuglxSdn8lWDyMF/UGZvNN 7OFZhZhRMOx0a5Hh1lXlvXIyd9oKx0kDcNVhK32YpHxdDZGIuNpd0c9f6r3SoGkNgolwGJVrS zqHpHNovV80GAwHW0NFNaV2V79kMHNoYHzt+s8NNp6odqO5rF5ioYxG7ypyOMfy6n/gr8O5nN l4txa09FMSqdo/8Icy8U7qb4HTNFizIZYQZL1h5TQISkjDBxVkDTxrRZuN9vEuEMDaaEMAb+S dOMRDHbIMypGvfEPwzrNTC/nssFozYHhttPN24RPe+MEBF3AvwwCLpJmafvreTdr99nfXfAeT 6K62OawgAL3Sssb+6omlEcHghqUrRgMwIUErLvKbeuKzO8gCFORAt854zh1/ozddWELHKwKJt RIn/Up8KbAqINDfagdkHGQMP0IZOc+P8Tr9IKoDKQpajRVVFU2ni0hVcEt8p60NwjM60Nr/Ac EpyaGU+ Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Thu, 15 Sep 2016 16:00:55 +0200 Move statements for error handling which were identical in two if branches to the end of these functions. Signed-off-by: Markus Elfring --- drivers/crypto/caam/caamhash.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index adb8b19..660dc20 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -1231,9 +1231,7 @@ static int ahash_final_no_ctx(struct ahash_request *req) state->buf_dma = dma_map_single(jrdev, buf, buflen, DMA_TO_DEVICE); if (dma_mapping_error(jrdev, state->buf_dma)) { dev_err(jrdev, "unable to map src\n"); - ahash_unmap(jrdev, edesc, req, digestsize); - kfree(edesc); - return -ENOMEM; + goto unmap; } append_seq_in_ptr(desc, state->buf_dma, buflen, 0); @@ -1242,9 +1240,7 @@ static int ahash_final_no_ctx(struct ahash_request *req) digestsize); if (dma_mapping_error(jrdev, edesc->dst_dma)) { dev_err(jrdev, "unable to map dst\n"); - ahash_unmap(jrdev, edesc, req, digestsize); - kfree(edesc); - return -ENOMEM; + goto unmap; } edesc->src_nents = 0; @@ -1262,6 +1258,11 @@ static int ahash_final_no_ctx(struct ahash_request *req) } return ret; + unmap: + ahash_unmap(jrdev, edesc, req, digestsize); + kfree(edesc); + return -ENOMEM; + } /* submit ahash update if it the first job descriptor after update */ @@ -1453,18 +1454,14 @@ static int ahash_finup_no_ctx(struct ahash_request *req) req->nbytes); if (ret) { dev_err(jrdev, "unable to map S/G table\n"); - ahash_unmap(jrdev, edesc, req, digestsize); - kfree(edesc); - return -ENOMEM; + goto unmap; } edesc->dst_dma = map_seq_out_ptr_result(desc, jrdev, req->result, digestsize); if (dma_mapping_error(jrdev, edesc->dst_dma)) { dev_err(jrdev, "unable to map dst\n"); - ahash_unmap(jrdev, edesc, req, digestsize); - kfree(edesc); - return -ENOMEM; + goto unmap; } #ifdef DEBUG @@ -1481,6 +1478,11 @@ static int ahash_finup_no_ctx(struct ahash_request *req) } return ret; + unmap: + ahash_unmap(jrdev, edesc, req, digestsize); + kfree(edesc); + return -ENOMEM; + } /* submit first update job descriptor after init */