Commit 5804509e authored by David S. Miller's avatar David S. Miller Committed by Jens Axboe

Fix loop terminating conditions in fill_sg().

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 60573b87
...@@ -475,12 +475,11 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr, ...@@ -475,12 +475,11 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
#define SG_ENT_PHYS_ADDRESS(SG) \ #define SG_ENT_PHYS_ADDRESS(SG) \
(__pa(page_address((SG)->page)) + (SG)->offset) (__pa(page_address((SG)->page)) + (SG)->offset)
static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, static void fill_sg(iopte_t *iopte, struct scatterlist *sg,
int nused, int nelems, int nused, int nelems,
unsigned long iopte_protection) unsigned long iopte_protection)
{ {
struct scatterlist *dma_sg = sg; struct scatterlist *dma_sg = sg;
struct scatterlist *sg_end = sg_last(sg, nelems);
int i; int i;
for (i = 0; i < nused; i++) { for (i = 0; i < nused; i++) {
...@@ -516,6 +515,7 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, ...@@ -516,6 +515,7 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
break; break;
} }
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
} }
pteval = iopte_protection | (pteval & IOPTE_PAGE); pteval = iopte_protection | (pteval & IOPTE_PAGE);
...@@ -529,18 +529,20 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg, ...@@ -529,18 +529,20 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
pteval = (pteval & IOPTE_PAGE) + len; pteval = (pteval & IOPTE_PAGE) + len;
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
/* Skip over any tail mappings we've fully mapped, /* Skip over any tail mappings we've fully mapped,
* adjusting pteval along the way. Stop when we * adjusting pteval along the way. Stop when we
* detect a page crossing event. * detect a page crossing event.
*/ */
while (sg != sg_end && while (nelems &&
(pteval << (64 - IO_PAGE_SHIFT)) != 0UL && (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
(pteval == SG_ENT_PHYS_ADDRESS(sg)) && (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
((pteval ^ ((pteval ^
(SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) { (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
pteval += sg->length; pteval += sg->length;
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
} }
if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL) if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
pteval = ~0UL; pteval = ~0UL;
......
...@@ -368,12 +368,11 @@ static void dma_4v_unmap_single(struct device *dev, dma_addr_t bus_addr, ...@@ -368,12 +368,11 @@ static void dma_4v_unmap_single(struct device *dev, dma_addr_t bus_addr,
#define SG_ENT_PHYS_ADDRESS(SG) \ #define SG_ENT_PHYS_ADDRESS(SG) \
(__pa(page_address((SG)->page)) + (SG)->offset) (__pa(page_address((SG)->page)) + (SG)->offset)
static inline long fill_sg(long entry, struct device *dev, static long fill_sg(long entry, struct device *dev,
struct scatterlist *sg, struct scatterlist *sg,
int nused, int nelems, unsigned long prot) int nused, int nelems, unsigned long prot)
{ {
struct scatterlist *dma_sg = sg; struct scatterlist *dma_sg = sg;
struct scatterlist *sg_end = sg_last(sg, nelems);
unsigned long flags; unsigned long flags;
int i; int i;
...@@ -414,6 +413,7 @@ static inline long fill_sg(long entry, struct device *dev, ...@@ -414,6 +413,7 @@ static inline long fill_sg(long entry, struct device *dev,
break; break;
} }
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
} }
pteval = (pteval & IOPTE_PAGE); pteval = (pteval & IOPTE_PAGE);
...@@ -432,19 +432,20 @@ static inline long fill_sg(long entry, struct device *dev, ...@@ -432,19 +432,20 @@ static inline long fill_sg(long entry, struct device *dev,
pteval = (pteval & IOPTE_PAGE) + len; pteval = (pteval & IOPTE_PAGE) + len;
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
/* Skip over any tail mappings we've fully mapped, /* Skip over any tail mappings we've fully mapped,
* adjusting pteval along the way. Stop when we * adjusting pteval along the way. Stop when we
* detect a page crossing event. * detect a page crossing event.
*/ */
while ((pteval << (64 - IO_PAGE_SHIFT)) != 0UL && while (nelems &&
(pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
(pteval == SG_ENT_PHYS_ADDRESS(sg)) && (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
((pteval ^ ((pteval ^
(SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) { (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
pteval += sg->length; pteval += sg->length;
if (sg == sg_end)
break;
sg = sg_next(sg); sg = sg_next(sg);
nelems--;
} }
if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL) if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
pteval = ~0UL; pteval = ~0UL;
......
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