public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-crypto@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Herbert Xu <herbert@gondor.apana.org.au>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/2] crypto-testmgr: Use common error handling code in drbg_cavs_test()
Date: Sat, 21 Oct 2017 17:53:54 +0000	[thread overview]
Message-ID: <7aa0ec0b-c00e-44c0-1c07-6bd87e2b6c47@users.sourceforge.net> (raw)
In-Reply-To: <7c2b4df8-a04b-cacd-13ba-4d9afb346263@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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;
 }
 
 
-- 
2.14.2


  reply	other threads:[~2017-10-21 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-21 17:52 [PATCH 0/2] crypto-testmgr: Fine-tuning for drbg_cavs_test() SF Markus Elfring
2017-10-21 17:53 ` SF Markus Elfring [this message]
2017-10-21 19:07   ` [PATCH 1/2] crypto-testmgr: Use common error handling code in drbg_cavs_test() Stephan Mueller
2017-10-21 20:00     ` SF Markus Elfring
2017-10-21 17:55 ` [PATCH 2/2] crypto-testmgr: Delete an unnecessary variable initialisation " SF Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7aa0ec0b-c00e-44c0-1c07-6bd87e2b6c47@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox