Commit 2694e23f authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu
Browse files

crypto: aesni - clean up mapping of associated data



The gcm(aes-ni) driver is only built for x86_64, which does not make
use of highmem. So testing for PageHighMem is pointless and can be
omitted.

While at it, replace GFP_ATOMIC with the appropriate runtime decided
value based on the context.

Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 30f2c18e
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -667,14 +667,15 @@ static int gcmaes_crypt_by_sg(bool enc, struct aead_request *req,
		gcm_tfm = &aesni_gcm_tfm_sse;
		gcm_tfm = &aesni_gcm_tfm_sse;


	/* Linearize assoc, if not already linear */
	/* Linearize assoc, if not already linear */
	if (req->src->length >= assoclen && req->src->length &&
	if (req->src->length >= assoclen && req->src->length) {
		(!PageHighMem(sg_page(req->src)) ||
			req->src->offset + req->src->length <= PAGE_SIZE)) {
		scatterwalk_start(&assoc_sg_walk, req->src);
		scatterwalk_start(&assoc_sg_walk, req->src);
		assoc = scatterwalk_map(&assoc_sg_walk);
		assoc = scatterwalk_map(&assoc_sg_walk);
	} else {
	} else {
		gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
			      GFP_KERNEL : GFP_ATOMIC;

		/* assoc can be any length, so must be on heap */
		/* assoc can be any length, so must be on heap */
		assocmem = kmalloc(assoclen, GFP_ATOMIC);
		assocmem = kmalloc(assoclen, flags);
		if (unlikely(!assocmem))
		if (unlikely(!assocmem))
			return -ENOMEM;
			return -ENOMEM;
		assoc = assocmem;
		assoc = assocmem;