]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: skcipher - Eliminate duplicate virt.addr field
authorHerbert Xu <herbert@gondor.apana.org.au>
Sat, 8 Mar 2025 12:45:25 +0000 (20:45 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 15 Mar 2025 08:21:22 +0000 (16:21 +0800)
Reuse the addr field from struct scatter_walk for skcipher_walk.

Keep the existing virt.addr fields but make them const for the
user to access the mapped address.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/skcipher.c
include/crypto/algapi.h
include/crypto/internal/skcipher.h

index 0c69111542415ba76a59b86c64d4de4f8c7694bd..ab5d852febcde8ab2f7c7003f512699abbb65c11 100644 (file)
@@ -43,14 +43,12 @@ static inline void skcipher_map_src(struct skcipher_walk *walk)
 {
        /* XXX */
        walk->in.__addr = scatterwalk_map(&walk->in);
-       walk->src.virt.addr = walk->in.addr;
 }
 
 static inline void skcipher_map_dst(struct skcipher_walk *walk)
 {
        /* XXX */
        walk->out.__addr = scatterwalk_map(&walk->out);
-       walk->dst.virt.addr = walk->out.addr;
 }
 
 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk)
@@ -100,8 +98,7 @@ int skcipher_walk_done(struct skcipher_walk *walk, int res)
                                    SKCIPHER_WALK_DIFF)))) {
                scatterwalk_advance(&walk->in, n);
        } else if (walk->flags & SKCIPHER_WALK_DIFF) {
-               scatterwalk_unmap(walk->src.virt.addr);
-               scatterwalk_advance(&walk->in, n);
+               scatterwalk_done_src(&walk->in, n);
        } else if (walk->flags & SKCIPHER_WALK_COPY) {
                scatterwalk_advance(&walk->in, n);
                skcipher_map_dst(walk);
@@ -116,11 +113,8 @@ int skcipher_walk_done(struct skcipher_walk *walk, int res)
                         */
                        res = -EINVAL;
                        total = 0;
-               } else {
-                       u8 *buf = PTR_ALIGN(walk->buffer, walk->alignmask + 1);
-
-                       memcpy_to_scatterwalk(&walk->out, buf, n);
-               }
+               } else
+                       memcpy_to_scatterwalk(&walk->out, walk->out.addr, n);
                goto dst_done;
        }
 
@@ -162,7 +156,7 @@ static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize)
 {
        unsigned alignmask = walk->alignmask;
        unsigned n;
-       u8 *buffer;
+       void *buffer;
 
        if (!walk->buffer)
                walk->buffer = walk->page;
@@ -176,10 +170,11 @@ static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize)
                        return skcipher_walk_done(walk, -ENOMEM);
                walk->buffer = buffer;
        }
-       walk->dst.virt.addr = PTR_ALIGN(buffer, alignmask + 1);
-       walk->src.virt.addr = walk->dst.virt.addr;
 
-       memcpy_from_scatterwalk(walk->src.virt.addr, &walk->in, bsize);
+       buffer = PTR_ALIGN(buffer, alignmask + 1);
+       memcpy_from_scatterwalk(buffer, &walk->in, bsize);
+       walk->out.__addr = buffer;
+       walk->in.__addr = walk->out.addr;
 
        walk->nbytes = bsize;
        walk->flags |= SKCIPHER_WALK_SLOW;
@@ -189,7 +184,7 @@ static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize)
 
 static int skcipher_next_copy(struct skcipher_walk *walk)
 {
-       u8 *tmp = walk->page;
+       void *tmp = walk->page;
 
        skcipher_map_src(walk);
        memcpy(tmp, walk->src.virt.addr, walk->nbytes);
@@ -199,8 +194,8 @@ static int skcipher_next_copy(struct skcipher_walk *walk)
         * processed (which might be less than walk->nbytes) is known.
         */
 
-       walk->src.virt.addr = tmp;
-       walk->dst.virt.addr = tmp;
+       walk->in.__addr = tmp;
+       walk->out.__addr = tmp;
        return 0;
 }
 
@@ -214,7 +209,7 @@ static int skcipher_next_fast(struct skcipher_walk *walk)
                (u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT));
 
        skcipher_map_dst(walk);
-       walk->src.virt.addr = walk->dst.virt.addr;
+       walk->in.__addr = walk->dst.virt.addr;
 
        if (diff) {
                walk->flags |= SKCIPHER_WALK_DIFF;
index f92e22686a68e8819206a284b26e774132282f0b..6e07bbc040895bf967ba41645d8532f0e0bb204d 100644 (file)
@@ -107,14 +107,15 @@ struct crypto_queue {
 };
 
 struct scatter_walk {
-       struct scatterlist *sg;
-       unsigned int offset;
+       /* Must be the first member, see struct skcipher_walk. */
        union {
                void *const addr;
 
                /* Private API field, do not touch. */
                union crypto_no_such_thing *__addr;
        };
+       struct scatterlist *sg;
+       unsigned int offset;
 };
 
 struct crypto_attr_alg {
index d6ae7a86fed23fc284c160e5bb4eba681623ee35..c705124432c58066420fd01d1f79ce7acca9ac4e 100644 (file)
@@ -56,15 +56,31 @@ struct crypto_lskcipher_spawn {
 
 struct skcipher_walk {
        union {
+               /* Virtual address of the source. */
                struct {
-                       void *addr;
-               } virt;
-       } src, dst;
+                       struct {
+                               void *const addr;
+                       } virt;
+               } src;
+
+               /* Private field for the API, do not use. */
+               struct scatter_walk in;
+       };
 
-       struct scatter_walk in;
        unsigned int nbytes;
 
-       struct scatter_walk out;
+       union {
+               /* Virtual address of the destination. */
+               struct {
+                       struct {
+                               void *const addr;
+                       } virt;
+               } dst;
+
+               /* Private field for the API, do not use. */
+               struct scatter_walk out;
+       };
+
        unsigned int total;
 
        u8 *page;