diff mbox series

[2/2] net: ll_temac: improve reset of buffer on dma mapping

Message ID 20230126101607.88407-2-jsc@umbraculum.org (mailing list archive)
State New, archived
Headers show
Series [1/2] net: ll_temac: fix DMA resources leak | expand

Commit Message

Jonas Suhr Christensen Jan. 26, 2023, 10:16 a.m. UTC
Free buffer and set pointer to null on dma mapping error.

Signed-off-by: Jonas Suhr Christensen <jsc@umbraculum.org>
---
 drivers/net/ethernet/xilinx/ll_temac_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski Jan. 28, 2023, 7:13 a.m. UTC | #1
On Thu, 26 Jan 2023 11:16:07 +0100 Jonas Suhr Christensen wrote:
> Free buffer and set pointer to null on dma mapping error.

Why? I don't see a leak. You should provide motivation in the commit
message.
Esben Haabendal Jan. 30, 2023, 12:40 p.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> writes:

> On Thu, 26 Jan 2023 11:16:07 +0100 Jonas Suhr Christensen wrote:
>> Free buffer and set pointer to null on dma mapping error.
>
> Why? I don't see a leak. You should provide motivation in the commit
> message.

I don't think there is a leak.  But if one of the dma_map_single() calls
in temac_dma_bd_init() fails, the error handling calls into
temac_dma_bd_release(), which will then call dma_unmap_single() on the
address that failed to be mapped.

Can we be sure that doing so is always safe?  If not, this change
ensures that we only unmap buffers that were succesfully mapped.

/Esben
Jakub Kicinski Jan. 30, 2023, 8:42 p.m. UTC | #3
On Mon, 30 Jan 2023 13:40:56 +0100 esben@geanix.com wrote:
> > On Thu, 26 Jan 2023 11:16:07 +0100 Jonas Suhr Christensen wrote:  
> >> Free buffer and set pointer to null on dma mapping error.  
> >
> > Why? I don't see a leak. You should provide motivation in the commit
> > message.  
> 
> I don't think there is a leak.  But if one of the dma_map_single() calls
> in temac_dma_bd_init() fails, the error handling calls into
> temac_dma_bd_release(), which will then call dma_unmap_single() on the
> address that failed to be mapped.

I see, seems worth fixing. Please explain that in the commit message,
it's not immediately clear what the concern is, otherwise.
On top of that please add a Fixes tag here as well and repost.

> Can we be sure that doing so is always safe?  If not, this change
> ensures that we only unmap buffers that were succesfully mapped.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 66c04027f230..5595ba57a126 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -376,8 +376,11 @@  static int temac_dma_bd_init(struct net_device *ndev)
 		skb_dma_addr = dma_map_single(ndev->dev.parent, skb->data,
 					      XTE_MAX_JUMBO_FRAME_SIZE,
 					      DMA_FROM_DEVICE);
-		if (dma_mapping_error(ndev->dev.parent, skb_dma_addr))
+		if (dma_mapping_error(ndev->dev.parent, skb_dma_addr)) {
+			dev_kfree_skb(lp->rx_skb[i]);
+			lp->rx_skb[i] = NULL;
 			goto out;
+		}
 		lp->rx_bd_v[i].phys = cpu_to_be32(skb_dma_addr);
 		lp->rx_bd_v[i].len = cpu_to_be32(XTE_MAX_JUMBO_FRAME_SIZE);
 		lp->rx_bd_v[i].app0 = cpu_to_be32(STS_CTRL_APP0_IRQONEND);