Commit ec027303 authored by Victoria Milhoan's avatar Victoria Milhoan Committed by Herbert Xu

crypto: caam - Use local sg pointers to walk the scatterlist

Avoid moving the head of the scatterlist entry by using temporary
pointers to walk the scatterlist.
Signed-off-by: default avatarVictoria Milhoan <vicki.milhoan@freescale.com>
Tested-by: default avatarHoria Geantă <horia.geanta@freescale.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7d5196ab
...@@ -105,9 +105,15 @@ static inline void dma_unmap_sg_chained( ...@@ -105,9 +105,15 @@ static inline void dma_unmap_sg_chained(
{ {
if (unlikely(chained)) { if (unlikely(chained)) {
int i; int i;
struct scatterlist *tsg = sg;
/*
* Use a local copy of the sg pointer to avoid moving the
* head of the list pointed to by sg as we walk the list.
*/
for (i = 0; i < nents; i++) { for (i = 0; i < nents; i++) {
dma_unmap_sg(dev, sg, 1, dir); dma_unmap_sg(dev, tsg, 1, dir);
sg = sg_next(sg); tsg = sg_next(tsg);
} }
} else if (nents) { } else if (nents) {
dma_unmap_sg(dev, sg, nents, dir); dma_unmap_sg(dev, sg, nents, dir);
...@@ -118,19 +124,23 @@ static inline int dma_map_sg_chained( ...@@ -118,19 +124,23 @@ static inline int dma_map_sg_chained(
struct device *dev, struct scatterlist *sg, unsigned int nents, struct device *dev, struct scatterlist *sg, unsigned int nents,
enum dma_data_direction dir, bool chained) enum dma_data_direction dir, bool chained)
{ {
struct scatterlist *first = sg;
if (unlikely(chained)) { if (unlikely(chained)) {
int i; int i;
struct scatterlist *tsg = sg;
/*
* Use a local copy of the sg pointer to avoid moving the
* head of the list pointed to by sg as we walk the list.
*/
for (i = 0; i < nents; i++) { for (i = 0; i < nents; i++) {
if (!dma_map_sg(dev, sg, 1, dir)) { if (!dma_map_sg(dev, tsg, 1, dir)) {
dma_unmap_sg_chained(dev, first, i, dir, dma_unmap_sg_chained(dev, sg, i, dir,
chained); chained);
nents = 0; nents = 0;
break; break;
} }
sg = sg_next(sg); tsg = sg_next(tsg);
} }
} else } else
nents = dma_map_sg(dev, sg, nents, dir); nents = dma_map_sg(dev, sg, nents, dir);
......
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