mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 18:43:33 +02:00
nvme-auth: use SHASH_DESC_ON_STACK
Use SHASH_DESC_ON_STACK to avoid explicit allocation. Signed-off-by: Hannes Reinecke <hare@kernel.org> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
87b4d5ec0d
commit
fee45888a3
|
|
@ -242,7 +242,7 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
|
|||
{
|
||||
const char *hmac_name;
|
||||
struct crypto_shash *key_tfm;
|
||||
struct shash_desc *shash;
|
||||
SHASH_DESC_ON_STACK(shash, key_tfm);
|
||||
struct nvme_dhchap_key *transformed_key;
|
||||
int ret, key_len;
|
||||
|
||||
|
|
@ -267,19 +267,11 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
|
|||
if (IS_ERR(key_tfm))
|
||||
return ERR_CAST(key_tfm);
|
||||
|
||||
shash = kmalloc(sizeof(struct shash_desc) +
|
||||
crypto_shash_descsize(key_tfm),
|
||||
GFP_KERNEL);
|
||||
if (!shash) {
|
||||
ret = -ENOMEM;
|
||||
goto out_free_key;
|
||||
}
|
||||
|
||||
key_len = crypto_shash_digestsize(key_tfm);
|
||||
transformed_key = nvme_auth_alloc_key(key_len, key->hash);
|
||||
if (!transformed_key) {
|
||||
ret = -ENOMEM;
|
||||
goto out_free_shash;
|
||||
goto out_free_key;
|
||||
}
|
||||
|
||||
shash->tfm = key_tfm;
|
||||
|
|
@ -299,15 +291,12 @@ struct nvme_dhchap_key *nvme_auth_transform_key(
|
|||
if (ret < 0)
|
||||
goto out_free_transformed_key;
|
||||
|
||||
kfree(shash);
|
||||
crypto_free_shash(key_tfm);
|
||||
|
||||
return transformed_key;
|
||||
|
||||
out_free_transformed_key:
|
||||
nvme_auth_free_key(transformed_key);
|
||||
out_free_shash:
|
||||
kfree(shash);
|
||||
out_free_key:
|
||||
crypto_free_shash(key_tfm);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user