Commit 6c94711c authored by Herbert Xu's avatar Herbert Xu

crypto: caam - Handle errors in dma_map_sg_chained

Currently dma_map_sg_chained does not handle errors from the
underlying dma_map_sg calls.  This patch adds rollback in case
of an error by simply calling dma_unmap_sg_chained for the ones
that we've already mapped.

All current callers ignore the return value so this should have
no impact on them.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 201f28f0
...@@ -100,34 +100,41 @@ static inline int sg_count(struct scatterlist *sg_list, int nbytes, ...@@ -100,34 +100,41 @@ static inline int sg_count(struct scatterlist *sg_list, int nbytes,
return sg_nents; return sg_nents;
} }
static int dma_map_sg_chained(struct device *dev, struct scatterlist *sg, static inline void dma_unmap_sg_chained(
unsigned int nents, enum dma_data_direction dir, struct device *dev, struct scatterlist *sg, unsigned int nents,
bool chained) enum dma_data_direction dir, bool chained)
{ {
if (unlikely(chained)) { if (unlikely(chained)) {
int i; int i;
for (i = 0; i < nents; i++) { for (i = 0; i < nents; i++) {
dma_map_sg(dev, sg, 1, dir); dma_unmap_sg(dev, sg, 1, dir);
sg = sg_next(sg); sg = sg_next(sg);
} }
} else { } else if (nents) {
dma_map_sg(dev, sg, nents, dir); dma_unmap_sg(dev, sg, nents, dir);
} }
return nents;
} }
static int dma_unmap_sg_chained(struct device *dev, struct scatterlist *sg, static inline int dma_map_sg_chained(
unsigned int nents, enum dma_data_direction dir, struct device *dev, struct scatterlist *sg, unsigned int nents,
bool chained) enum dma_data_direction dir, bool chained)
{ {
struct scatterlist *first = sg;
if (unlikely(chained)) { if (unlikely(chained)) {
int i; int i;
for (i = 0; i < nents; i++) { for (i = 0; i < nents; i++) {
dma_unmap_sg(dev, sg, 1, dir); if (!dma_map_sg(dev, sg, 1, dir)) {
dma_unmap_sg_chained(dev, first, i, dir,
chained);
nents = 0;
break;
}
sg = sg_next(sg); sg = sg_next(sg);
} }
} else { } else
dma_unmap_sg(dev, sg, nents, dir); nents = dma_map_sg(dev, sg, nents, dir);
}
return nents; return nents;
} }
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