Skip to contentSkip to conversation

crypto: scatterwalk - simplify map and unmap calling convention

PATCH In review Eric Biggers 2 participants 2 messages Mar 10, 2025 – Mar 21, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: scatterwalk - simplify map and unmap calling convention

From: Eric Biggers <[email protected]>

Now that the address returned by scatterwalk_map() is always being stored into the same struct scatter_walk that is passed in, make scatterwalk_map() do so itself and return void.

Similarly, now that scatterwalk_unmap() is always being passed the address field within a struct scatter_walk, make scatterwalk_unmap() take a pointer to struct scatter_walk instead of the address directly.

---
 arch/s390/crypto/aes_s390.c  |  3 +--
 crypto/skcipher.c            | 28 +++++++----------------
 include/crypto/scatterwalk.h | 43 ++++++++++++++++++++----------------
 3 files changed, 33 insertions(+), 41 deletions(-)
arch/s390/crypto/aes_s390.c +1 -2
index ed85bd6e298f5..5d36f4020dfa3 100644
@@ -869,12 +869,11 @@ static int gcm_out_walk_go(struct gcm_sg_walk *gw, unsigned int minbytesneeded)
 		gw->ptr = gw->walk.addr;
 		gw->nbytes = gw->walk_bytes;
 		goto out;
 	}
 
-	/* XXX */
-	scatterwalk_unmap(gw->walk.addr);
+	scatterwalk_unmap(&gw->walk);
 
 	gw->ptr = gw->buf;
 	gw->nbytes = sizeof(gw->buf);
 
 out:
crypto/skcipher.c +8 -20
index ab5d852febcde..132075a905d99 100644
@@ -37,22 +37,10 @@ enum {
 
 static const struct crypto_type crypto_skcipher_type;
 
 static int skcipher_walk_next(struct skcipher_walk *walk);
 
-static inline void skcipher_map_src(struct skcipher_walk *walk)
-{
-	/* XXX */
-	walk->in.__addr = scatterwalk_map(&walk->in);
-}
-
-static inline void skcipher_map_dst(struct skcipher_walk *walk)
-{
-	/* XXX */
-	walk->out.__addr = scatterwalk_map(&walk->out);
-}
-
 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk)
 {
 	return walk->flags & SKCIPHER_WALK_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
 }
 
@@ -99,12 +87,12 @@ int skcipher_walk_done(struct skcipher_walk *walk, int res)
 		scatterwalk_advance(&walk->in, n);
 	} else if (walk->flags & SKCIPHER_WALK_DIFF) {
 		scatterwalk_done_src(&walk->in, n);
 	} else if (walk->flags & SKCIPHER_WALK_COPY) {
 		scatterwalk_advance(&walk->in, n);
-		skcipher_map_dst(walk);
-		memcpy(walk->dst.virt.addr, walk->page, n);
+		scatterwalk_map(&walk->out);
+		memcpy(walk->out.addr, walk->page, n);
 	} else { /* SKCIPHER_WALK_SLOW */
 		if (res > 0) {
 			/*
 			 * Didn't process all bytes.  Either the algorithm is
 			 * broken, or this was the last step and it turned out
@@ -184,13 +172,13 @@ static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize)
 
 static int skcipher_next_copy(struct skcipher_walk *walk)
 {
 	void *tmp = walk->page;
 
-	skcipher_map_src(walk);
-	memcpy(tmp, walk->src.virt.addr, walk->nbytes);
-	scatterwalk_unmap(walk->src.virt.addr);
+	scatterwalk_map(&walk->in);
+	memcpy(tmp, walk->in.addr, walk->nbytes);
+	scatterwalk_unmap(&walk->in);
 	/*
 	 * walk->in is advanced later when the number of bytes actually
 	 * processed (which might be less than walk->nbytes) is known.
 	 */
 
@@ -206,16 +194,16 @@ static int skcipher_next_fast(struct skcipher_walk *walk)
 	diff = offset_in_page(walk->in.offset) -
 	       offset_in_page(walk->out.offset);
 	diff |= (u8 *)(sg_page(walk->in.sg) + (walk->in.offset >> PAGE_SHIFT)) -
 		(u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT));
 
-	skcipher_map_dst(walk);
-	walk->in.__addr = walk->dst.virt.addr;
+	scatterwalk_map(&walk->out);
+	walk->in.__addr = walk->out.__addr;
 
 	if (diff) {
 		walk->flags |= SKCIPHER_WALK_DIFF;
-		skcipher_map_src(walk);
+		scatterwalk_map(&walk->in);
 	}
 
 	return 0;
 }
 
include/crypto/scatterwalk.h +24 -19

91 lines not on this page · raw message

base-commit: eca6828403b80343647de39d4782ee56cc9e36dd
prerequisite-patch-id: 2ea677b85c3108d6431e6b873b161c2c119071ad
prerequisite-patch-id: 53dd3a1a8327e9f4301e21502f2cba5ef4808b4a
prerequisite-patch-id: 45b81fdd96514ba844b8b3fec2130bd287540f99

Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 10 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Now that the address returned by scatterwalk_map() is always being stored into the same struct scatter_walk that is passed in, make scatterwalk_map() do so itself and return void.

Similarly, now that scatterwalk_unmap() is always being passed the address field within a struct scatter_walk, make scatterwalk_unmap() take a pointer to struct scatter_walk instead of the address directly.

Quoted 6 lines

---

arch/s390/crypto/aes_s390.c  |  3 +--
crypto/skcipher.c            | 28 +++++++----------------
include/crypto/scatterwalk.h | 43 ++++++++++++++++++++----------------
3 files changed, 33 insertions(+), 41 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt