diff options
author | Harsh Jain <harsh@chelsio.com> | 2017-01-24 00:04:33 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-02-03 04:45:44 -0500 |
commit | f5f7bebc91ab378dea5aad5277c4d283e46472d9 (patch) | |
tree | da94e5d483aa22d9dbb77d8ed573335d84a0373b | |
parent | 94e1dab1c94715e18bb0bada503de3f3d7593076 (diff) |
crypto: chcr - Check device is allocated before use
Ensure dev is allocated for crypto uld context before using the device
for crypto operations.
Cc: <stable@vger.kernel.org>
Signed-off-by: Atul Gupta <atul.gupta@chelsio.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-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 918da8e6e2d8..1c65f07e1cc9 100644 --- a/drivers/crypto/chelsio/chcr_core.c +++ b/drivers/crypto/chelsio/chcr_core.c | |||
@@ -52,6 +52,7 @@ static struct cxgb4_uld_info chcr_uld_info = { | |||
52 | int assign_chcr_device(struct chcr_dev **dev) | 52 | int assign_chcr_device(struct chcr_dev **dev) |
53 | { | 53 | { |
54 | struct uld_ctx *u_ctx; | 54 | struct uld_ctx *u_ctx; |
55 | int ret = -ENXIO; | ||
55 | 56 | ||
56 | /* | 57 | /* |
57 | * Which device to use if multiple devices are available TODO | 58 | * Which device to use if multiple devices are available TODO |
@@ -59,15 +60,14 @@ int assign_chcr_device(struct chcr_dev **dev) | |||
59 | * must go to the same device to maintain the ordering. | 60 | * must go to the same device to maintain the ordering. |
60 | */ | 61 | */ |
61 | mutex_lock(&dev_mutex); /* TODO ? */ | 62 | mutex_lock(&dev_mutex); /* TODO ? */ |
62 | u_ctx = list_first_entry(&uld_ctx_list, struct uld_ctx, entry); | 63 | list_for_each_entry(u_ctx, &uld_ctx_list, entry) |
63 | if (!u_ctx) { | 64 | if (u_ctx && u_ctx->dev) { |
64 | mutex_unlock(&dev_mutex); | 65 | *dev = u_ctx->dev; |
65 | return -ENXIO; | 66 | ret = 0; |
67 | break; | ||
66 | } | 68 | } |
67 | |||
68 | *dev = u_ctx->dev; | ||
69 | mutex_unlock(&dev_mutex); | 69 | mutex_unlock(&dev_mutex); |
70 | return 0; | 70 | return ret; |
71 | } | 71 | } |
72 | 72 | ||
73 | static int chcr_dev_add(struct uld_ctx *u_ctx) | 73 | 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) | |||
202 | 202 | ||
203 | static int __init chcr_crypto_init(void) | 203 | static int __init chcr_crypto_init(void) |
204 | { | 204 | { |
205 | if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info)) { | 205 | if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info)) |
206 | pr_err("ULD register fail: No chcr crypto support in cxgb4"); | 206 | pr_err("ULD register fail: No chcr crypto support in cxgb4"); |
207 | return -1; | ||
208 | } | ||
209 | 207 | ||
210 | return 0; | 208 | return 0; |
211 | } | 209 | } |