Skip to contentSkip to conversation

DMA: nbpfaxi: check for errors from dma_map_single

PATCH In review Jesper Nilsson 2 participants 2 messages Oct 5, 2016 – Oct 18, 2016 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DMA: nbpfaxi: check for errors from dma_map_single

Check for error return from dma_map_single.
Move the addition of the node to the list to after we check for error, so we can reuse the list in unmapping.

Found by enabling CONFIG_DMA_API_DEBUG.

---
 drivers/dma/nbpfaxi.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/dma/nbpfaxi.c +14 -1
index 42ac2ff..4f5dd2e 100644
@@ -731,10 +731,15 @@ static int __nbpf_desc_page_alloc(struct nbpf_channel *chan, gfp_t gfp)
 	     i < ARRAY_SIZE(dpage->ldesc);
 	     i++, ldesc++, hwdesc++) {
 		ldesc->hwdesc = hwdesc;
-		list_add_tail(&ldesc->node, &lhead);
 		ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev,
 					hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE);
 
+		if (dma_mapping_error(dchan->device->dev,
+				      ldesc->hwdesc_dma_addr)) {
+			goto unmap_err;
+		}
+		list_add_tail(&ldesc->node, &lhead);
+
 		dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__,
 			hwdesc, &ldesc->hwdesc_dma_addr);
 	}
@@ -754,6 +759,14 @@ static int __nbpf_desc_page_alloc(struct nbpf_channel *chan, gfp_t gfp)
 	list_add(&dpage->node, &chan->desc_page);
 
 	return ARRAY_SIZE(dpage->desc);
+unmap_err:
+	list_for_each_entry(ldesc, &lhead, node) {
+		dma_unmap_single(dchan->device->dev,
+				 ldesc->hwdesc_dma_addr,
+				 sizeof(*ldesc->hwdesc),
+				 DMA_TO_DEVICE);
+	}
+	return -ENOMEM;
 }
 
 static void __nbpf_desc_put(struct nbpf_desc *desc)
Signature · 6 lines
2.1.4


/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- [email protected]
#1 lore raw
Quoted 5 lines · Jesper Nilsson

Check for error return from dma_map_single.
Move the addition of the node to the list to after we check for error, so we can reuse the list in unmapping.

Found by enabling CONFIG_DMA_API_DEBUG.

Sorry this doesnt apply for me, cna you rebase and resend.

While at it, please use right subsystem name. dmaengine: nbpfaxi:...

Signature · 1 line
~Vinod