Commit 6c503d0d authored by Christoph Hellwig's avatar Christoph Hellwig

sparc/iommu: fix ->map_sg return value

Just decrementing the sz value will lead to an incorrect return value.
Instead of just introducing a local variable switch to the standard
for_each_sg helper and standard naming of the arguments.

Fixes: ce65d36f ("sparc: remove the sparc32_dma_ops indirection")
Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 1e2934ad
...@@ -241,32 +241,31 @@ static dma_addr_t sbus_iommu_map_page_pflush(struct device *dev, ...@@ -241,32 +241,31 @@ static dma_addr_t sbus_iommu_map_page_pflush(struct device *dev,
return __sbus_iommu_map_page(dev, page, offset, len); return __sbus_iommu_map_page(dev, page, offset, len);
} }
static int sbus_iommu_map_sg_gflush(struct device *dev, struct scatterlist *sg, static int sbus_iommu_map_sg_gflush(struct device *dev, struct scatterlist *sgl,
int sz, enum dma_data_direction dir, unsigned long attrs) int nents, enum dma_data_direction dir, unsigned long attrs)
{ {
int n; struct scatterlist *sg;
int i, n;
flush_page_for_dma(0); flush_page_for_dma(0);
while (sz != 0) {
--sz; for_each_sg(sgl, sg, nents, i) {
n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT; n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT;
sg->dma_address = iommu_get_one(dev, sg_page(sg), n) + sg->offset; sg->dma_address = iommu_get_one(dev, sg_page(sg), n) + sg->offset;
sg->dma_length = sg->length; sg->dma_length = sg->length;
sg = sg_next(sg);
} }
return sz; return nents;
} }
static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sg, static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl,
int sz, enum dma_data_direction dir, unsigned long attrs) int nents, enum dma_data_direction dir, unsigned long attrs)
{ {
unsigned long page, oldpage = 0; unsigned long page, oldpage = 0;
int n, i; struct scatterlist *sg;
int i, j, n;
while(sz != 0) {
--sz;
for_each_sg(sgl, sg, nents, j) {
n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT; n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT;
/* /*
...@@ -286,10 +285,9 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sg, ...@@ -286,10 +285,9 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sg,
sg->dma_address = iommu_get_one(dev, sg_page(sg), n) + sg->offset; sg->dma_address = iommu_get_one(dev, sg_page(sg), n) + sg->offset;
sg->dma_length = sg->length; sg->dma_length = sg->length;
sg = sg_next(sg);
} }
return sz; return nents;
} }
static void iommu_release_one(struct device *dev, u32 busa, int npages) static void iommu_release_one(struct device *dev, u32 busa, int npages)
...@@ -318,17 +316,16 @@ static void sbus_iommu_unmap_page(struct device *dev, dma_addr_t dma_addr, ...@@ -318,17 +316,16 @@ static void sbus_iommu_unmap_page(struct device *dev, dma_addr_t dma_addr,
iommu_release_one(dev, dma_addr & PAGE_MASK, npages); iommu_release_one(dev, dma_addr & PAGE_MASK, npages);
} }
static void sbus_iommu_unmap_sg(struct device *dev, struct scatterlist *sg, static void sbus_iommu_unmap_sg(struct device *dev, struct scatterlist *sgl,
int sz, enum dma_data_direction dir, unsigned long attrs) int nents, enum dma_data_direction dir, unsigned long attrs)
{ {
int n; struct scatterlist *sg;
int i, n;
while(sz != 0) { for_each_sg(sgl, sg, nents, i) {
--sz;
n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT; n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT;
iommu_release_one(dev, sg->dma_address & PAGE_MASK, n); iommu_release_one(dev, sg->dma_address & PAGE_MASK, n);
sg->dma_address = 0x21212121; sg->dma_address = 0x21212121;
sg = sg_next(sg);
} }
} }
......
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