Skip to content

Commit 1cfd9f3

Browse files
Tero Kristoherbertx
authored andcommitted
crypto: omap-sham - fix unaligned sg list handling
Currently the offset for unaligned sg lists is not handled properly leading into wrong results with certain testmgr self tests. Fix the handling to account for proper offset within the current sg list. Signed-off-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5d5f3ee commit 1cfd9f3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/crypto/omap-sham.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,20 @@ static int omap_sham_copy_sg_lists(struct omap_sham_reqctx *ctx,
673673
while (sg && new_len) {
674674
int len = sg->length - offset;
675675

676-
if (offset) {
676+
if (len <= 0) {
677677
offset -= sg->length;
678-
if (offset < 0)
679-
offset = 0;
678+
sg = sg_next(sg);
679+
continue;
680680
}
681681

682682
if (new_len < len)
683683
len = new_len;
684684

685685
if (len > 0) {
686686
new_len -= len;
687-
sg_set_page(tmp, sg_page(sg), len, sg->offset);
687+
sg_set_page(tmp, sg_page(sg), len, sg->offset + offset);
688+
offset = 0;
689+
ctx->offset = 0;
688690
ctx->sg_len++;
689691
if (new_len <= 0)
690692
break;
@@ -834,7 +836,14 @@ static int omap_sham_align_sgs(struct scatterlist *sg,
834836
rctx->total = new_len;
835837
rctx->offset += new_len;
836838
rctx->sg_len = n;
837-
rctx->sg = sg;
839+
if (rctx->bufcnt) {
840+
sg_init_table(rctx->sgl, 2);
841+
sg_set_buf(rctx->sgl, rctx->dd->xmit_buf, rctx->bufcnt);
842+
sg_chain(rctx->sgl, 2, sg);
843+
rctx->sg = rctx->sgl;
844+
} else {
845+
rctx->sg = sg;
846+
}
838847

839848
return 0;
840849
}

0 commit comments

Comments
 (0)