diff options
author | Harsh Jain <harsh@chelsio.com> | 2017-01-24 00:04:33 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-02-14 18:25:32 -0500 |
commit | b4de8af91b8ab9a604a5acd78b0d8763cf5818b5 (patch) | |
tree | ae23d37d835f4768c1578041814d7db520a4c0a6 | |
parent | 066a7166c5412ea4c04b1946faf2aa7cda48ee60 (diff) |
crypto: chcr - Check device is allocated before use
commit f5f7bebc91ab378dea5aad5277c4d283e46472d9 upstream.
Ensure dev is allocated for crypto uld context before using the device
for crypto operations.
Signed-off-by: Atul Gupta <atul.gupta@chelsio.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/crypto/chelsio/chcr_core.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/drivers/crypto/chelsio/chcr_core.c b/drivers/crypto/chelsio/chcr_core.c index fb5f9bbfa09c..6aece3f25b08 100644 --- a/drivers/crypto/chelsio/chcr_core.c +++ b/drivers/crypto/chelsio/chcr_core.c | |||
@@ -51,6 +51,7 @@ static struct cxgb4_uld_info chcr_uld_info = { | |||
51 | int assign_chcr_device(struct chcr_dev **dev) | 51 | int assign_chcr_device(struct chcr_dev **dev) |
52 | { | 52 | { |
53 | struct uld_ctx *u_ctx; | 53 | struct uld_ctx *u_ctx; |
54 | int ret = -ENXIO; | ||
54 | 55 | ||
55 | /* | 56 | /* |
56 | * Which device to use if multiple devices are available TODO | 57 | * Which device to use if multiple devices are available TODO |
@@ -58,15 +59,14 @@ int assign_chcr_device(struct chcr_dev **dev) | |||
58 | * must go to the same device to maintain the ordering. | 59 | * must go to the same device to maintain the ordering. |
59 | */ | 60 | */ |
60 | mutex_lock(&dev_mutex); /* TODO ? */ | 61 | mutex_lock(&dev_mutex); /* TODO ? */ |
61 | u_ctx = list_first_entry(&uld_ctx_list, struct uld_ctx, entry); | 62 | list_for_each_entry(u_ctx, &uld_ctx_list, entry) |
62 | if (!u_ctx) { | 63 | if (u_ctx && u_ctx->dev) { |
63 | mutex_unlock(&dev_mutex); | 64 | *dev = u_ctx->dev; |
64 | return -ENXIO; | 65 | ret = 0; |
66 | break; | ||
65 | } | 67 | } |
66 | |||
67 | *dev = u_ctx->dev; | ||
68 | mutex_unlock(&dev_mutex); | 68 | mutex_unlock(&dev_mutex); |
69 | return 0; | 69 | return ret; |
70 | } | 70 | } |
71 | 71 | ||
72 | static int chcr_dev_add(struct uld_ctx *u_ctx) | 72 | static int chcr_dev_add(struct uld_ctx *u_ctx) |
@@ -203,10 +203,8 @@ static int chcr_uld_state_change(void *handle, enum cxgb4_state state) | |||
203 | 203 | ||
204 | static int __init chcr_crypto_init(void) | 204 | static int __init chcr_crypto_init(void) |
205 | { | 205 | { |
206 | if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info)) { | 206 | if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info)) |
207 | pr_err("ULD register fail: No chcr crypto support in cxgb4"); | 207 | pr_err("ULD register fail: No chcr crypto support in cxgb4"); |
208 | return -1; | ||
209 | } | ||
210 | 208 | ||
211 | return 0; | 209 | return 0; |
212 | } | 210 | } |