Skip to content

Commit e7d5d8a

Browse files
ebiggersherbertx
authored andcommitted
crypto: s390/aes-gcm - use the new scatterwalk functions
Use scatterwalk_next() which consolidates scatterwalk_clamp() and scatterwalk_map(). Use scatterwalk_done_src() and scatterwalk_done_dst() which consolidate scatterwalk_unmap(), scatterwalk_advance(), and scatterwalk_done(). Besides the new functions being a bit easier to use, this is necessary because scatterwalk_done() is planned to be removed. Reviewed-by: Harald Freudenberger <freude@linux.ibm.com> Tested-by: Harald Freudenberger <freude@linux.ibm.com> Cc: Holger Dengler <dengler@linux.ibm.com> Cc: linux-s390@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 422bf8f commit e7d5d8a

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

arch/s390/crypto/aes_s390.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -787,28 +787,21 @@ static void gcm_walk_start(struct gcm_sg_walk *gw, struct scatterlist *sg,
787787

788788
static inline unsigned int _gcm_sg_clamp_and_map(struct gcm_sg_walk *gw)
789789
{
790-
struct scatterlist *nextsg;
791-
792-
gw->walk_bytes = scatterwalk_clamp(&gw->walk, gw->walk_bytes_remain);
793-
while (!gw->walk_bytes) {
794-
nextsg = sg_next(gw->walk.sg);
795-
if (!nextsg)
796-
return 0;
797-
scatterwalk_start(&gw->walk, nextsg);
798-
gw->walk_bytes = scatterwalk_clamp(&gw->walk,
799-
gw->walk_bytes_remain);
800-
}
801-
gw->walk_ptr = scatterwalk_map(&gw->walk);
790+
if (gw->walk_bytes_remain == 0)
791+
return 0;
792+
gw->walk_ptr = scatterwalk_next(&gw->walk, gw->walk_bytes_remain,
793+
&gw->walk_bytes);
802794
return gw->walk_bytes;
803795
}
804796

805797
static inline void _gcm_sg_unmap_and_advance(struct gcm_sg_walk *gw,
806-
unsigned int nbytes)
798+
unsigned int nbytes, bool out)
807799
{
808800
gw->walk_bytes_remain -= nbytes;
809-
scatterwalk_unmap(gw->walk_ptr);
810-
scatterwalk_advance(&gw->walk, nbytes);
811-
scatterwalk_done(&gw->walk, 0, gw->walk_bytes_remain);
801+
if (out)
802+
scatterwalk_done_dst(&gw->walk, gw->walk_ptr, nbytes);
803+
else
804+
scatterwalk_done_src(&gw->walk, gw->walk_ptr, nbytes);
812805
gw->walk_ptr = NULL;
813806
}
814807

@@ -844,7 +837,7 @@ static int gcm_in_walk_go(struct gcm_sg_walk *gw, unsigned int minbytesneeded)
844837
n = min(gw->walk_bytes, AES_BLOCK_SIZE - gw->buf_bytes);
845838
memcpy(gw->buf + gw->buf_bytes, gw->walk_ptr, n);
846839
gw->buf_bytes += n;
847-
_gcm_sg_unmap_and_advance(gw, n);
840+
_gcm_sg_unmap_and_advance(gw, n, false);
848841
if (gw->buf_bytes >= minbytesneeded) {
849842
gw->ptr = gw->buf;
850843
gw->nbytes = gw->buf_bytes;
@@ -904,7 +897,7 @@ static int gcm_in_walk_done(struct gcm_sg_walk *gw, unsigned int bytesdone)
904897
} else
905898
gw->buf_bytes = 0;
906899
} else
907-
_gcm_sg_unmap_and_advance(gw, bytesdone);
900+
_gcm_sg_unmap_and_advance(gw, bytesdone, false);
908901

909902
return bytesdone;
910903
}
@@ -922,10 +915,10 @@ static int gcm_out_walk_done(struct gcm_sg_walk *gw, unsigned int bytesdone)
922915
return i;
923916
n = min(gw->walk_bytes, bytesdone - i);
924917
memcpy(gw->walk_ptr, gw->buf + i, n);
925-
_gcm_sg_unmap_and_advance(gw, n);
918+
_gcm_sg_unmap_and_advance(gw, n, true);
926919
}
927920
} else
928-
_gcm_sg_unmap_and_advance(gw, bytesdone);
921+
_gcm_sg_unmap_and_advance(gw, bytesdone, true);
929922

930923
return bytesdone;
931924
}

0 commit comments

Comments
 (0)