linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harsh Jain <harsh@chelsio.com>
To: hariprasad@chelsio.com, netdev@vger.kernel.org,
	herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org
Cc: Harsh Jain <harsh@chelsio.com>, Atul Gupta <atul.gupta@chelsio.com>
Subject: [PATCH v1 7/8] crypto:chcr- Check device is allocated before use
Date: Fri,  6 Jan 2017 14:01:38 +0530	[thread overview]
Message-ID: <8e0086b56d8fb61637d179c32a09a1bca03c4186.1483599449.git.harsh@chelsio.com> (raw)
In-Reply-To: <cover.1483599449.git.harsh@chelsio.com>
In-Reply-To: <cover.1483599449.git.harsh@chelsio.com>

Ensure dev is allocated for crypto uld context before using the device
for crypto operations.

Signed-off-by: Atul Gupta <atul.gupta@chelsio.com>
---
 drivers/crypto/chelsio/chcr_core.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_core.c b/drivers/crypto/chelsio/chcr_core.c
index 918da8e..1c65f07 100644
--- a/drivers/crypto/chelsio/chcr_core.c
+++ b/drivers/crypto/chelsio/chcr_core.c
@@ -52,6 +52,7 @@
 int assign_chcr_device(struct chcr_dev **dev)
 {
 	struct uld_ctx *u_ctx;
+	int ret = -ENXIO;
 
 	/*
 	 * Which device to use if multiple devices are available TODO
@@ -59,15 +60,14 @@ int assign_chcr_device(struct chcr_dev **dev)
 	 * must go to the same device to maintain the ordering.
 	 */
 	mutex_lock(&dev_mutex); /* TODO ? */
-	u_ctx = list_first_entry(&uld_ctx_list, struct uld_ctx, entry);
-	if (!u_ctx) {
-		mutex_unlock(&dev_mutex);
-		return -ENXIO;
+	list_for_each_entry(u_ctx, &uld_ctx_list, entry)
+		if (u_ctx && u_ctx->dev) {
+			*dev = u_ctx->dev;
+			ret = 0;
+			break;
 	}
-
-	*dev = u_ctx->dev;
 	mutex_unlock(&dev_mutex);
-	return 0;
+	return ret;
 }
 
 static int chcr_dev_add(struct uld_ctx *u_ctx)
@@ -202,10 +202,8 @@ static int chcr_uld_state_change(void *handle, enum cxgb4_state state)
 
 static int __init chcr_crypto_init(void)
 {
-	if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info)) {
+	if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info))
 		pr_err("ULD register fail: No chcr crypto support in cxgb4");
-		return -1;
-	}
 
 	return 0;
 }
-- 
1.8.2.3

  parent reply	other threads:[~2017-01-06  8:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06  8:31 [PATCH v1 0/8] crypto:chcr- Bug fixes Harsh Jain
2017-01-06  8:31 ` [PATCH v1 1/8] crypto:chcr-Change flow IDs Harsh Jain
2017-01-06  8:31 ` [PATCH v1 2/8] crypto:chcr- Fix panic on dma_unmap_sg Harsh Jain
2017-01-06  8:31 ` [PATCH v1 3/8] crypto:chcr- Fix key length for RFC4106 Harsh Jain
2017-01-12 16:09   ` Herbert Xu
2017-01-12 16:38     ` Harsh Jain
2017-01-12 16:42       ` Herbert Xu
2017-01-06  8:31 ` [PATCH v1 4/8] crypto:chcr- Use cipher instead of Block Cipher in gcm setkey Harsh Jain
2017-01-06  8:31 ` [PATCH v1 5/8] crypto:chcr: Change cra_flags for cipher algos Harsh Jain
2017-01-06  8:31 ` [PATCH v1 6/8] crypto:chcr- Change algo priority Harsh Jain
2017-01-06  8:31 ` Harsh Jain [this message]
2017-01-06  8:31 ` [PATCH v1 8/8] crypto:chcr- Fix wrong typecasting Harsh Jain
2017-01-12 16:14 ` [PATCH v1 0/8] crypto:chcr- Bug fixes Herbert Xu

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=8e0086b56d8fb61637d179c32a09a1bca03c4186.1483599449.git.harsh@chelsio.com \
    --to=harsh@chelsio.com \
    --cc=atul.gupta@chelsio.com \
    --cc=hariprasad@chelsio.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).