Skip to content

Commit f7038b7

Browse files
Sebastian OttMartin Schwidefsky
authored andcommitted
s390/pci/dma: fix accounting of allocated_pages
allocated_pages sometimes are increased even if s390_dma_alloc fails also this value is never decreased even if s390_dma_free is called. This patch fixes these bugs. Also remove the atomic64_t casts (the members are already of this type). Reviewed-by: Gerald Schaefer <[email protected]> Signed-off-by: Sebastian Ott <[email protected]> Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent 0c0c277 commit f7038b7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/s390/pci/pci_dma.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static dma_addr_t s390_dma_map_pages(struct device *dev, struct page *page,
285285
flags |= ZPCI_TABLE_PROTECTED;
286286

287287
if (!dma_update_trans(zdev, pa, dma_addr, size, flags)) {
288-
atomic64_add(nr_pages, (atomic64_t *) &zdev->fmb->mapped_pages);
288+
atomic64_add(nr_pages, &zdev->fmb->mapped_pages);
289289
return dma_addr + (offset & ~PAGE_MASK);
290290
}
291291

@@ -313,7 +313,7 @@ static void s390_dma_unmap_pages(struct device *dev, dma_addr_t dma_addr,
313313
zpci_err_hex(&dma_addr, sizeof(dma_addr));
314314
}
315315

316-
atomic64_add(npages, (atomic64_t *) &zdev->fmb->unmapped_pages);
316+
atomic64_add(npages, &zdev->fmb->unmapped_pages);
317317
iommu_page_index = (dma_addr - zdev->start_dma) >> PAGE_SHIFT;
318318
dma_free_iommu(zdev, iommu_page_index, npages);
319319
}
@@ -332,7 +332,6 @@ static void *s390_dma_alloc(struct device *dev, size_t size,
332332
if (!page)
333333
return NULL;
334334

335-
atomic64_add(size / PAGE_SIZE, (atomic64_t *) &zdev->fmb->allocated_pages);
336335
pa = page_to_phys(page);
337336
memset((void *) pa, 0, size);
338337

@@ -343,6 +342,7 @@ static void *s390_dma_alloc(struct device *dev, size_t size,
343342
return NULL;
344343
}
345344

345+
atomic64_add(size / PAGE_SIZE, &zdev->fmb->allocated_pages);
346346
if (dma_handle)
347347
*dma_handle = map;
348348
return (void *) pa;
@@ -352,8 +352,11 @@ static void s390_dma_free(struct device *dev, size_t size,
352352
void *pa, dma_addr_t dma_handle,
353353
struct dma_attrs *attrs)
354354
{
355-
s390_dma_unmap_pages(dev, dma_handle, PAGE_ALIGN(size),
356-
DMA_BIDIRECTIONAL, NULL);
355+
struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
356+
357+
size = PAGE_ALIGN(size);
358+
atomic64_sub(size / PAGE_SIZE, &zdev->fmb->allocated_pages);
359+
s390_dma_unmap_pages(dev, dma_handle, size, DMA_BIDIRECTIONAL, NULL);
357360
free_pages((unsigned long) pa, get_order(size));
358361
}
359362

0 commit comments

Comments
 (0)