Commit 74412fd5 authored by Herbert Xu's avatar Herbert Xu

crypto: scatterwalk - Check for same address in map_and_copy

This patch adds a check for in scatterwalk_map_and_copy to avoid
copying from the same address to the same address.  This is going
to be used for IV copying in AEAD IV generators.

There is no provision for partial overlaps.

This patch also uses the new scatterwalk_ffwd instead of doing
it by hand in scatterwalk_map_and_copy.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 17db8546
...@@ -104,22 +104,18 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, ...@@ -104,22 +104,18 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
unsigned int start, unsigned int nbytes, int out) unsigned int start, unsigned int nbytes, int out)
{ {
struct scatter_walk walk; struct scatter_walk walk;
unsigned int offset = 0; struct scatterlist tmp[2];
if (!nbytes) if (!nbytes)
return; return;
for (;;) { sg = scatterwalk_ffwd(tmp, sg, start);
scatterwalk_start(&walk, sg);
if (start < offset + sg->length)
break;
offset += sg->length; if (sg_page(sg) == virt_to_page(buf) &&
sg = sg_next(sg); sg->offset == offset_in_page(buf))
} return;
scatterwalk_advance(&walk, start - offset); scatterwalk_start(&walk, sg);
scatterwalk_copychunks(buf, &walk, nbytes, out); scatterwalk_copychunks(buf, &walk, nbytes, out);
scatterwalk_done(&walk, out, 0); scatterwalk_done(&walk, out, 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment