diff options
| author | Jason Gunthorpe <jgg@mellanox.com> | 2019-01-04 13:40:21 -0500 |
|---|---|---|
| committer | Jason Gunthorpe <jgg@mellanox.com> | 2019-02-11 17:02:33 -0500 |
| commit | d901b2760dc6cd5fbbf2eac31d71d94baa6c4aef (patch) | |
| tree | 6598a5b011cea1bcdf160c2be9fd4e677d387e2b /lib | |
| parent | f368ff188ae4b3ef6f740a15999ea0373261b619 (diff) | |
lib/scatterlist: Provide a DMA page iterator
Commit 2db76d7c3c6d ("lib/scatterlist: sg_page_iter: support sg lists w/o
backing pages") introduced the sg_page_iter_dma_address() function without
providing a way to use it in the general case. If the sg_dma_len() is not
equal to the sg length callers cannot safely use the
for_each_sg_page/sg_page_iter_dma_address combination.
Resolve this API mistake by providing a DMA specific iterator,
for_each_sg_dma_page(), that uses the right length so
sg_page_iter_dma_address() works as expected with all sglists.
A new iterator type is introduced to provide compile-time safety against
wrongly mixing accessors and iterators.
Acked-by: Christoph Hellwig <hch@lst.de> (for scatterlist)
Acked-by: Thomas Hellstrom <thellstrom@vmware.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> (ipu3-cio2)
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/scatterlist.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 9ba349e775ef..739dc9fe2c55 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
| @@ -625,6 +625,32 @@ bool __sg_page_iter_next(struct sg_page_iter *piter) | |||
| 625 | } | 625 | } |
| 626 | EXPORT_SYMBOL(__sg_page_iter_next); | 626 | EXPORT_SYMBOL(__sg_page_iter_next); |
| 627 | 627 | ||
| 628 | static int sg_dma_page_count(struct scatterlist *sg) | ||
| 629 | { | ||
| 630 | return PAGE_ALIGN(sg->offset + sg_dma_len(sg)) >> PAGE_SHIFT; | ||
| 631 | } | ||
| 632 | |||
| 633 | bool __sg_page_iter_dma_next(struct sg_dma_page_iter *dma_iter) | ||
| 634 | { | ||
| 635 | struct sg_page_iter *piter = &dma_iter->base; | ||
| 636 | |||
| 637 | if (!piter->__nents || !piter->sg) | ||
| 638 | return false; | ||
| 639 | |||
| 640 | piter->sg_pgoffset += piter->__pg_advance; | ||
| 641 | piter->__pg_advance = 1; | ||
| 642 | |||
| 643 | while (piter->sg_pgoffset >= sg_dma_page_count(piter->sg)) { | ||
| 644 | piter->sg_pgoffset -= sg_dma_page_count(piter->sg); | ||
| 645 | piter->sg = sg_next(piter->sg); | ||
| 646 | if (!--piter->__nents || !piter->sg) | ||
| 647 | return false; | ||
| 648 | } | ||
| 649 | |||
| 650 | return true; | ||
| 651 | } | ||
| 652 | EXPORT_SYMBOL(__sg_page_iter_dma_next); | ||
| 653 | |||
| 628 | /** | 654 | /** |
| 629 | * sg_miter_start - start mapping iteration over a sg list | 655 | * sg_miter_start - start mapping iteration over a sg list |
| 630 | * @miter: sg mapping iter to be started | 656 | * @miter: sg mapping iter to be started |
