nfsd: use crypto_shash_tfm_digest()

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-nfs@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Eric Biggers 2020-05-01 22:31:17 -07:00 committed by Herbert Xu
parent 1979811388
commit ea794db264

View File

@ -127,16 +127,8 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
goto out; goto out;
} }
{ status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
SHASH_DESC_ON_STACK(desc, tfm); cksum.data);
desc->tfm = tfm;
status = crypto_shash_digest(desc, clname->data, clname->len,
cksum.data);
shash_desc_zero(desc);
}
if (status) if (status)
goto out; goto out;
@ -1148,7 +1140,6 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
struct crypto_shash *tfm = cn->cn_tfm; struct crypto_shash *tfm = cn->cn_tfm;
struct xdr_netobj cksum; struct xdr_netobj cksum;
char *principal = NULL; char *principal = NULL;
SHASH_DESC_ON_STACK(desc, tfm);
/* Don't upcall if it's already stored */ /* Don't upcall if it's already stored */
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags)) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
@ -1170,16 +1161,14 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
else if (clp->cl_cred.cr_principal) else if (clp->cl_cred.cr_principal)
principal = clp->cl_cred.cr_principal; principal = clp->cl_cred.cr_principal;
if (principal) { if (principal) {
desc->tfm = tfm;
cksum.len = crypto_shash_digestsize(tfm); cksum.len = crypto_shash_digestsize(tfm);
cksum.data = kmalloc(cksum.len, GFP_KERNEL); cksum.data = kmalloc(cksum.len, GFP_KERNEL);
if (cksum.data == NULL) { if (cksum.data == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
ret = crypto_shash_digest(desc, principal, strlen(principal), ret = crypto_shash_tfm_digest(tfm, principal, strlen(principal),
cksum.data); cksum.data);
shash_desc_zero(desc);
if (ret) { if (ret) {
kfree(cksum.data); kfree(cksum.data);
goto out; goto out;
@ -1343,7 +1332,6 @@ nfsd4_cld_check_v2(struct nfs4_client *clp)
struct crypto_shash *tfm = cn->cn_tfm; struct crypto_shash *tfm = cn->cn_tfm;
struct xdr_netobj cksum; struct xdr_netobj cksum;
char *principal = NULL; char *principal = NULL;
SHASH_DESC_ON_STACK(desc, tfm);
/* did we already find that this client is stable? */ /* did we already find that this client is stable? */
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags)) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
@ -1381,14 +1369,12 @@ found:
principal = clp->cl_cred.cr_principal; principal = clp->cl_cred.cr_principal;
if (principal == NULL) if (principal == NULL)
return -ENOENT; return -ENOENT;
desc->tfm = tfm;
cksum.len = crypto_shash_digestsize(tfm); cksum.len = crypto_shash_digestsize(tfm);
cksum.data = kmalloc(cksum.len, GFP_KERNEL); cksum.data = kmalloc(cksum.len, GFP_KERNEL);
if (cksum.data == NULL) if (cksum.data == NULL)
return -ENOENT; return -ENOENT;
status = crypto_shash_digest(desc, principal, strlen(principal), status = crypto_shash_tfm_digest(tfm, principal,
cksum.data); strlen(principal), cksum.data);
shash_desc_zero(desc);
if (status) { if (status) {
kfree(cksum.data); kfree(cksum.data);
return -ENOENT; return -ENOENT;