lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161005145131.GJ30704@axis.com>
Date:   Wed, 5 Oct 2016 16:51:32 +0200
From:   Jesper Nilsson <jesper.nilsson@...s.com>
To:     Dan Williams <dan.j.williams@...el.com>,
        Vinod Koul <vinod.koul@...el.com>, dmaengine@...r.kernel.org,
        Guennadi Liakhovetski <g.liakhovetski@....de>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] 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.

Signed-off-by: Jesper Nilsson <jesper.nilsson@...s.com>
---
 drivers/dma/nbpfaxi.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c
index 42ac2ff..4f5dd2e 100644
--- a/drivers/dma/nbpfaxi.c
+++ b/drivers/dma/nbpfaxi.c
@@ -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)
-- 
2.1.4


/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@...s.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ