Thread (33 messages) flat view 33 messages, 2 authors, 2021-05-14

Re: [PATCH v2 15/22] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg

From: Christoph Hellwig <hch@lst.de>
Date: 2021-05-14 13:57:23
Also in: linux-iommu, linux-mm, linux-nvme, linux-pci, lkml

+	for_each_sg(sgl, sg, nents, i) {
+		if (sg_is_dma_pci_p2pdma(sg)) {
+			sg_dma_unmark_pci_p2pdma(sg);
+		} else  {
Double space here.  We also don't really need the curly braces to start
with.
+	struct pci_p2pdma_map_state p2pdma_state = {};
+	enum pci_p2pdma_map_type map;
 	struct scatterlist *sg;
+	int i, ret;
 
 	for_each_sg(sgl, sg, nents, i) {
+		if (is_pci_p2pdma_page(sg_page(sg))) {
+			map = pci_p2pdma_map_segment(&p2pdma_state, dev, sg);
+			switch (map) {
Why not just:

			switch (pci_p2pdma_map_segment(&p2pdma_state, dev,
					sg)) {

(even better with a shorter name for p2pdma_state so that it all fits on
a single line)?
+			case PCI_P2PDMA_MAP_BUS_ADDR:
+				continue;
+			case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
+				/*
+				 * Mapping through host bridge should be
+				 * mapped normally, thus we do nothing
+				 * and continue below.
+				 */
I have a bit of a hard time parsing this comment.
quoted hunk ↗ jump to hunk
+		if (sg->dma_address == DMA_MAPPING_ERROR) {
+			ret = -EINVAL;
 			goto out_unmap;
+		}
 		sg_dma_len(sg) = sg->length;
 	}
 
@@ -411,7 +443,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 
 out_unmap:
 	dma_direct_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC);
-	return -EINVAL;
+	return ret;
Maybe just initialize ret to -EINVAL at declaration time to simplify this
a bit?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help