mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
crypto: omap-crypto - copy the temporary data to output buffer properly
Both source and destination are scatterlists that can contain multiple entries under the omap crypto cleanup handling. Current code only copies data from the first source scatterlist entry to the target scatterlist, potentially omitting any sg entries following the first one. Instead, implement a new routine that walks through both source and target and copies the data over once it goes. Signed-off-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
aca8bf0027
commit
839bb2a9ca
@ -154,6 +154,41 @@ int omap_crypto_align_sg(struct scatterlist **sg, int total, int bs,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(omap_crypto_align_sg);
|
||||
|
||||
static void omap_crypto_copy_data(struct scatterlist *src,
|
||||
struct scatterlist *dst,
|
||||
int offset, int len)
|
||||
{
|
||||
int amt;
|
||||
void *srcb, *dstb;
|
||||
int srco = 0, dsto = offset;
|
||||
|
||||
while (src && dst && len) {
|
||||
if (srco >= src->length) {
|
||||
srco -= src->length;
|
||||
src = sg_next(src);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dsto >= dst->length) {
|
||||
dsto -= dst->length;
|
||||
dst = sg_next(dst);
|
||||
continue;
|
||||
}
|
||||
|
||||
amt = min(src->length - srco, dst->length - dsto);
|
||||
amt = min(len, amt);
|
||||
|
||||
srcb = sg_virt(src) + srco;
|
||||
dstb = sg_virt(dst) + dsto;
|
||||
|
||||
memcpy(dstb, srcb, amt);
|
||||
|
||||
srco += amt;
|
||||
dsto += amt;
|
||||
len -= amt;
|
||||
}
|
||||
}
|
||||
|
||||
void omap_crypto_cleanup(struct scatterlist *sg, struct scatterlist *orig,
|
||||
int offset, int len, u8 flags_shift,
|
||||
unsigned long flags)
|
||||
@ -171,7 +206,7 @@ void omap_crypto_cleanup(struct scatterlist *sg, struct scatterlist *orig,
|
||||
pages = get_order(len);
|
||||
|
||||
if (orig && (flags & OMAP_CRYPTO_COPY_MASK))
|
||||
scatterwalk_map_and_copy(buf, orig, offset, len, 1);
|
||||
omap_crypto_copy_data(sg, orig, offset, len);
|
||||
|
||||
if (flags & OMAP_CRYPTO_DATA_COPIED)
|
||||
free_pages((unsigned long)buf, pages);
|
||||
|
Loading…
Reference in New Issue
Block a user