Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: skcipher - Eliminate duplicate virt.addr field

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>

+36 -24
+12 -17
crypto/skcipher.c
··· 43 43 { 44 44 /* XXX */ 45 45 walk->in.__addr = scatterwalk_map(&walk->in); 46 - walk->src.virt.addr = walk->in.addr; 47 46 } 48 47 49 48 static inline void skcipher_map_dst(struct skcipher_walk *walk) 50 49 { 51 50 /* XXX */ 52 51 walk->out.__addr = scatterwalk_map(&walk->out); 53 - walk->dst.virt.addr = walk->out.addr; 54 52 } 55 53 56 54 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) ··· 98 100 SKCIPHER_WALK_DIFF)))) { 99 101 scatterwalk_advance(&walk->in, n); 100 102 } else if (walk->flags & SKCIPHER_WALK_DIFF) { 101 - scatterwalk_unmap(walk->src.virt.addr); 102 - scatterwalk_advance(&walk->in, n); 103 + scatterwalk_done_src(&walk->in, n); 103 104 } else if (walk->flags & SKCIPHER_WALK_COPY) { 104 105 scatterwalk_advance(&walk->in, n); 105 106 skcipher_map_dst(walk); ··· 113 116 */ 114 117 res = -EINVAL; 115 118 total = 0; 116 - } else { 117 - u8 *buf = PTR_ALIGN(walk->buffer, walk->alignmask + 1); 118 - 119 - memcpy_to_scatterwalk(&walk->out, buf, n); 120 - } 119 + } else 120 + memcpy_to_scatterwalk(&walk->out, walk->out.addr, n); 121 121 goto dst_done; 122 122 } 123 123 ··· 156 162 { 157 163 unsigned alignmask = walk->alignmask; 158 164 unsigned n; 159 - u8 *buffer; 165 + void *buffer; 160 166 161 167 if (!walk->buffer) 162 168 walk->buffer = walk->page; ··· 170 176 return skcipher_walk_done(walk, -ENOMEM); 171 177 walk->buffer = buffer; 172 178 } 173 - walk->dst.virt.addr = PTR_ALIGN(buffer, alignmask + 1); 174 - walk->src.virt.addr = walk->dst.virt.addr; 175 179 176 - memcpy_from_scatterwalk(walk->src.virt.addr, &walk->in, bsize); 180 + buffer = PTR_ALIGN(buffer, alignmask + 1); 181 + memcpy_from_scatterwalk(buffer, &walk->in, bsize); 182 + walk->out.__addr = buffer; 183 + walk->in.__addr = walk->out.addr; 177 184 178 185 walk->nbytes = bsize; 179 186 walk->flags |= SKCIPHER_WALK_SLOW; ··· 184 189 185 190 static int skcipher_next_copy(struct skcipher_walk *walk) 186 191 { 187 - u8 *tmp = walk->page; 192 + void *tmp = walk->page; 188 193 189 194 skcipher_map_src(walk); 190 195 memcpy(tmp, walk->src.virt.addr, walk->nbytes); ··· 194 199 * processed (which might be less than walk->nbytes) is known. 195 200 */ 196 201 197 - walk->src.virt.addr = tmp; 198 - walk->dst.virt.addr = tmp; 202 + walk->in.__addr = tmp; 203 + walk->out.__addr = tmp; 199 204 return 0; 200 205 } 201 206 ··· 209 214 (u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT)); 210 215 211 216 skcipher_map_dst(walk); 212 - walk->src.virt.addr = walk->dst.virt.addr; 217 + walk->in.__addr = walk->dst.virt.addr; 213 218 214 219 if (diff) { 215 220 walk->flags |= SKCIPHER_WALK_DIFF;
+3 -2
include/crypto/algapi.h
··· 107 107 }; 108 108 109 109 struct scatter_walk { 110 - struct scatterlist *sg; 111 - unsigned int offset; 110 + /* Must be the first member, see struct skcipher_walk. */ 112 111 union { 113 112 void *const addr; 114 113 115 114 /* Private API field, do not touch. */ 116 115 union crypto_no_such_thing *__addr; 117 116 }; 117 + struct scatterlist *sg; 118 + unsigned int offset; 118 119 }; 119 120 120 121 struct crypto_attr_alg {
+21 -5
include/crypto/internal/skcipher.h
··· 56 56 57 57 struct skcipher_walk { 58 58 union { 59 + /* Virtual address of the source. */ 59 60 struct { 60 - void *addr; 61 - } virt; 62 - } src, dst; 61 + struct { 62 + void *const addr; 63 + } virt; 64 + } src; 63 65 64 - struct scatter_walk in; 66 + /* Private field for the API, do not use. */ 67 + struct scatter_walk in; 68 + }; 69 + 65 70 unsigned int nbytes; 66 71 67 - struct scatter_walk out; 72 + union { 73 + /* Virtual address of the destination. */ 74 + struct { 75 + struct { 76 + void *const addr; 77 + } virt; 78 + } dst; 79 + 80 + /* Private field for the API, do not use. */ 81 + struct scatter_walk out; 82 + }; 83 + 68 84 unsigned int total; 69 85 70 86 u8 *page;