[PATCH 4/6] net: designware: don't use dma_mapping_error for non-streaming DMA

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Oct 14 05:58:41 PDT 2024


Streaming DMA operates at already allocated memory and the mapping needs
to be checked for errors with dma_mapping_error().

Calling it on the DMA address resulting from dma_alloc_coherent is
wrong, because error is indicated by returning a NULL pointer as CPU
address; The DMA address may not be set at all in that case.

While fixing this I wondered why priv->[tr]x_mac_descrtable_dev appear
to be unused. That's not the case, because they are used indirectly via
a helper function defined in a header, so add a comment about this while
we are at it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/designware.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 66f28b429dea..e7735a014cf4 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -480,18 +480,20 @@ struct dw_eth_dev *dwc_drv_probe(struct device *dev)
 	dwc_version(dev, readl(&priv->mac_regs_p->version));
 	priv->dma_regs_p = base + DW_DMA_BASE_OFFSET;
 
+	/* [tr]x_mac_descrtable_dev will be used by the [tr]x_dma_addr helpers */
+
 	priv->tx_mac_descrtable_cpu = dma_alloc_coherent(
 		CONFIG_TX_DESCR_NUM * sizeof(struct dmamacdescr),
 		&priv->tx_mac_descrtable_dev);
 
-	if (dma_mapping_error(dev, priv->tx_mac_descrtable_dev))
+	if (!priv->tx_mac_descrtable_cpu)
 		return ERR_PTR(-EFAULT);
 
 	priv->rx_mac_descrtable_cpu = dma_alloc_coherent(
 		CONFIG_RX_DESCR_NUM * sizeof(struct dmamacdescr),
 		&priv->rx_mac_descrtable_dev);
 
-	if (dma_mapping_error(dev, priv->rx_mac_descrtable_dev))
+	if (!priv->rx_mac_descrtable_cpu)
 		return ERR_PTR(-EFAULT);
 
 	priv->txbuffs = dma_alloc(TX_TOTAL_BUFSIZE);
-- 
2.39.5




More information about the barebox mailing list