[PATCH] ppc64: iommu vmerge fix

This fixes a bug in the PPC64 iommu vmerge code which results in the
potential for iommu_unmap_sg to go off unmapping more than it should.

This was found on a test system which resulted in PCI bus errors due to
PCI memory being unmapped while DMAs were still in progress.

Signed-off-by: Brian King <brking@us.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Brian King and committed by Linus Torvalds ac9af7cb 75e8727f

+4 -3
+4 -3
arch/ppc64/kernel/iommu.c
··· 242 242 dma_addr_t dma_next = 0, dma_addr; 243 243 unsigned long flags; 244 244 struct scatterlist *s, *outs, *segstart; 245 - int outcount; 245 + int outcount, incount; 246 246 unsigned long handle; 247 247 248 248 BUG_ON(direction == DMA_NONE); ··· 252 252 253 253 outs = s = segstart = &sglist[0]; 254 254 outcount = 1; 255 + incount = nelems; 255 256 handle = 0; 256 257 257 258 /* Init first segment length for backout at failure */ ··· 339 338 340 339 DBG("mapped %d elements:\n", outcount); 341 340 342 - /* For the sake of iommu_free_sg, we clear out the length in the 341 + /* For the sake of iommu_unmap_sg, we clear out the length in the 343 342 * next entry of the sglist if we didn't fill the list completely 344 343 */ 345 - if (outcount < nelems) { 344 + if (outcount < incount) { 346 345 outs++; 347 346 outs->dma_address = DMA_ERROR_CODE; 348 347 outs->dma_length = 0;