From patchwork Sat Oct 21 17:53:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10021475 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 E175D60224 for ; Sat, 21 Oct 2017 17:54:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2A0E2223E for ; Sat, 21 Oct 2017 17:54:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6FEA2865F; Sat, 21 Oct 2017 17:54:34 +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=unavailable 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 8352B2223E for ; Sat, 21 Oct 2017 17:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932228AbdJURyI (ORCPT ); Sat, 21 Oct 2017 13:54:08 -0400 Received: from mout.web.de ([212.227.15.14]:53053 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbdJURyG (ORCPT ); Sat, 21 Oct 2017 13:54:06 -0400 Received: from [192.168.1.2] ([78.49.207.83]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MYI9h-1djoP73Jsf-00VB2t; Sat, 21 Oct 2017 19:53:56 +0200 Subject: [PATCH 1/2] crypto-testmgr: Use common error handling code in drbg_cavs_test() From: SF Markus Elfring To: linux-crypto@vger.kernel.org, "David S. Miller" , Herbert Xu Cc: LKML , kernel-janitors@vger.kernel.org References: <7c2b4df8-a04b-cacd-13ba-4d9afb346263@users.sourceforge.net> Message-ID: <7aa0ec0b-c00e-44c0-1c07-6bd87e2b6c47@users.sourceforge.net> Date: Sat, 21 Oct 2017 19:53:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <7c2b4df8-a04b-cacd-13ba-4d9afb346263@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:dU8rTXgiUvdrv6Ajpl68gZMduU2+wrpyAgTePR1uTw7/VgE/hac EwKSioseakeHIv/Bgu9u8lXCQayCm5gOivwRVKZ7rntt99wVkxEQ7kaiPj5stUc/7rxq20t tmGT9XVTf8nWmGtG/Bh6AHHzd6hDrGMIpncAXlFEKaZFJ9x5E/bqhapJuuP3wgsy5s7iyf2 568rhcYbUW+bmJ5Vu0Keg== X-UI-Out-Filterresults: notjunk:1; V01:K0:2JBEFM1m2d0=:AjJH+WjH0lAj4QbTNennnA x9InYRvvLDXMbKxWohHGEYaKD48TVwW2zYT172a+XhBY7BhJgwPAQ4+UpUn3QYVx3PvdNE6u9 EMNJvxvy12b+CiSsttMDlZMsNMBw6v12VqM5mIGMUk6uXS+oQcrxDyRfXLrdLvK7UM34rAPHf Z2HrJGRtuZ8RxYVybvwKJvUCC/iEskGpmKuGbVI+Hi4yeYAgmIDRaff9okFkl4yJEpqcJsYB9 rauWNftVWKhZmXxeHvmPaJGN4VBCe7y8s8UDzRcfSZFQEYybgpBSagyFkVJgc3eqJgpDaTMCi rCKd5iruWCFL4IKtWiuYUCMNxTNkCGkMKMaIEHrmWxvvJZdnMseqmOME1jsA6y1IqihjEA0yd Z1mBh/uLKMHOAEAtX6M0Y8UT8oGWluyrN4wLkZzUgUoC1muweOg4+s9HPxaybuniEHcV5UPM/ apmaY7M2kLmnZn75LxybZkvofwsPGi08aKTtzAdBoqO8nvQDZvIrP/3KD2PwriAX4wt8bkKIv vpSOlQouiVGjMqVEKEf4hjcB1Oi9JLXStWoKszP7cu9PHE1V11SAG8KSLAdQcBkJP95qZu0dn zcfmQaVq/wytMWBF994TSrvrx1Fr/efzKD2IBf9VXckmfBC2EZizLYA+BFDAtwVNvGS7knvyL oxIOAiggOgss62Uay4EoVsnBn+GnpW9QQUpjMt+HZy1VxyuFaOjqunyMBHq/d7p4B3F3rPsLC FVZaKqQrS/fzIe/8G97YOjdT8Yj5gG+50NxRXU7sNC+bJiuq/S3fohR8tkL8OJLmlwsu4tdFW Twauq0GUUOE+hZ+cCF4XM1ddVUJseskcN5MiMBnTyB0dBnBktE= 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: Sat, 21 Oct 2017 19:29:11 +0200 Adjust jump targets so that a bit of exception handling can be better reused at the end of this function. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- crypto/testmgr.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index dd9c7f1c1c7b..76c5128284f8 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -1914,8 +1914,8 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr, if (IS_ERR(drng)) { printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " "%s\n", driver); - kzfree(buf); - return -ENOMEM; + ret = -ENOMEM; + goto free_buffer; } test_data.testentropy = &testentropy; @@ -1924,7 +1924,7 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr, ret = crypto_drbg_reset_test(drng, &pers, &test_data); if (ret) { printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); - goto outbuf; + goto free_rng; } drbg_string_fill(&addtl, test->addtla, test->addtllen); @@ -1936,11 +1936,9 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr, ret = crypto_drbg_get_bytes_addtl(drng, buf, test->expectedlen, &addtl); } - if (ret < 0) { - printk(KERN_ERR "alg: drbg: could not obtain random data for " - "driver %s\n", driver); - goto outbuf; - } + + if (ret < 0) + goto report_failure; drbg_string_fill(&addtl, test->addtlb, test->addtllen); if (pr) { @@ -1951,18 +1949,21 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr, ret = crypto_drbg_get_bytes_addtl(drng, buf, test->expectedlen, &addtl); } - if (ret < 0) { - printk(KERN_ERR "alg: drbg: could not obtain random data for " - "driver %s\n", driver); - goto outbuf; - } - ret = memcmp(test->expected, buf, test->expectedlen); + if (ret < 0) + goto report_failure; -outbuf: + ret = memcmp(test->expected, buf, test->expectedlen); +free_rng: crypto_free_rng(drng); +free_buffer: kzfree(buf); return ret; + +report_failure: + pr_err("alg: drbg: could not obtain random data for driver %s\n", + driver); + goto free_rng; }