Skip to contentSkip to conversation

ntb_perf: Adjustments for perf_copy_chunk()

PATCH New Markus Elfring 1 participant 3 messages Sep 23, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ntb_perf: Adjustments for perf_copy_chunk()

From: Markus Elfring <[email protected]>
Date: Mon, 23 Sep 2024 11:00:22 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Delete duplicate dmaengine_unmap_put() call
Use common error handling code

 drivers/ntb/test/ntb_perf.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

--
2.46.1

#1 lore raw

PATCH 1/2 ntb_perf: Delete duplicate dmaengine_unmap_put() call in perf_copy_chunk()

From: Markus Elfring <[email protected]>
Date: Mon, 23 Sep 2024 10:38:11 +0200

The function call “dmaengine_unmap_put(unmap)” was used in an if branch. The same call was immediately triggered by a subsequent goto statement. Thus avoid such a call repetition.

This issue was detected by using the Coccinelle software.

Fixes 5648e56d03fa ("NTB: ntb_perf: Add full multi-port NTB API support")

---

I imagine that a single function call “dmaengine_unmap_put(unmap)” can be sufficient for this use case.
https://elixir.bootlin.com/linux/v6.11/source/drivers/dma/dmaengine.c#L1377

How do you think about to improve resource management any further?

 drivers/ntb/test/ntb_perf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/ntb/test/ntb_perf.c +1 -3
index 72bc1d017a46..dfd175f79e8f 100644
@@ -839,10 +839,8 @@ static int perf_copy_chunk(struct perf_thread *pthr,
 	dma_set_unmap(tx, unmap);
 
 	ret = dma_submit_error(dmaengine_submit(tx));
-	if (ret) {
-		dmaengine_unmap_put(unmap);
+	if (ret)
 		goto err_free_resource;
-	}
 
 	dmaengine_unmap_put(unmap);
 

--
2.46.1

#2 lore raw

PATCH 2/2 ntb_perf: Use common error handling code in perf_copy_chunk()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 23 Sep 2024 10:48:17 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

---
 drivers/ntb/test/ntb_perf.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/ntb/test/ntb_perf.c +7 -8
index dfd175f79e8f..88c5192b81eb 100644
@@ -816,10 +816,9 @@ static int perf_copy_chunk(struct perf_thread *pthr,
 	unmap->len = len;
 	unmap->addr[0] = dma_map_page(dma_dev, virt_to_page(src),
 		offset_in_page(src), len, DMA_TO_DEVICE);
-	if (dma_mapping_error(dma_dev, unmap->addr[0])) {
-		ret = -EIO;
-		goto err_free_resource;
-	}
+	if (dma_mapping_error(dma_dev, unmap->addr[0]))
+		goto e_io;
+
 	unmap->to_cnt = 1;
 
 	do {
@@ -829,10 +828,8 @@ static int perf_copy_chunk(struct perf_thread *pthr,
 			msleep(DMA_MDELAY);
 	} while (!tx && (try++ < DMA_TRIES));
 
-	if (!tx) {
-		ret = -EIO;
-		goto err_free_resource;
-	}
+	if (!tx)
+		goto e_io;
 
 	tx->callback = perf_dma_copy_callback;
 	tx->callback_param = pthr;
@@ -850,6 +847,8 @@ static int perf_copy_chunk(struct perf_thread *pthr,
 ret_check_tsync:
 	return likely(atomic_read(&pthr->perf->tsync) > 0) ? 0 : -EINTR;
 
+e_io:
+	ret = -EIO;
 err_free_resource:
 	dmaengine_unmap_put(unmap);
 

--
2.46.1