linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs
@ 2019-12-15  1:10 Navid Emamdoost
  2019-12-15 14:27 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Navid Emamdoost @ 2019-12-15  1:10 UTC (permalink / raw)
  To: Hans Ulli Kroll, Linus Walleij, David S. Miller,
	Michał Mirosław, linux-arm-kernel, netdev,
	linux-kernel
  Cc: emamd001, Navid Emamdoost

In the implementation of gmac_setup_txqs() the allocated desc_ring is
leaked if TX queue base is not aligned. Release it via
dma_free_coherent.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/net/ethernet/cortina/gemini.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index a8f4c69252ff..3a796fe099dd 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -576,6 +576,8 @@ static int gmac_setup_txqs(struct net_device *netdev)
 
 	if (port->txq_dma_base & ~DMA_Q_BASE_MASK) {
 		dev_warn(geth->dev, "TX queue base is not aligned\n");
+		dma_free_coherent(geth->dev, len * sizeof(*desc_ring),
+				  desc_ring, port->txq_dma_base);
 		kfree(skb_tab);
 		return -ENOMEM;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs
  2019-12-15  1:10 [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs Navid Emamdoost
@ 2019-12-15 14:27 ` Markus Elfring
  2019-12-16 10:20 ` Linus Walleij
  2019-12-17  0:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-12-15 14:27 UTC (permalink / raw)
  To: Navid Emamdoost, linux-arm-kernel, netdev
  Cc: linux-kernel, kernel-janitors, David S. Miller, Linus Walleij,
	Michał Mirosław, Navid Emamdoost, Hans Ulli Kroll

> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -576,6 +576,8 @@ static int gmac_setup_txqs(struct net_device *netdev)
>
>  	if (port->txq_dma_base & ~DMA_Q_BASE_MASK) {
>  		dev_warn(geth->dev, "TX queue base is not aligned\n");
> +		dma_free_coherent(geth->dev, len * sizeof(*desc_ring),
> +				  desc_ring, port->txq_dma_base);
>  		kfree(skb_tab);
>  		return -ENOMEM;
>  	}

The added function call seems to be fine.
Would you like to avoid a bit of duplicate code for the exception handling?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs
  2019-12-15  1:10 [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs Navid Emamdoost
  2019-12-15 14:27 ` Markus Elfring
@ 2019-12-16 10:20 ` Linus Walleij
  2019-12-17  0:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2019-12-16 10:20 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: Hans Ulli Kroll, David S. Miller, Michał Mirosław,
	Linux ARM, netdev, linux-kernel, emamd001

On Sun, Dec 15, 2019 at 2:11 AM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:

> In the implementation of gmac_setup_txqs() the allocated desc_ring is
> leaked if TX queue base is not aligned. Release it via
> dma_free_coherent.
>
> Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>

Looks correct to me,
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs
  2019-12-15  1:10 [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs Navid Emamdoost
  2019-12-15 14:27 ` Markus Elfring
  2019-12-16 10:20 ` Linus Walleij
@ 2019-12-17  0:27 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-12-17  0:27 UTC (permalink / raw)
  To: navid.emamdoost
  Cc: ulli.kroll, linus.walleij, mirq-linux, linux-arm-kernel, netdev,
	linux-kernel, emamd001

From: Navid Emamdoost <navid.emamdoost@gmail.com>
Date: Sat, 14 Dec 2019 19:10:44 -0600

> In the implementation of gmac_setup_txqs() the allocated desc_ring is
> leaked if TX queue base is not aligned. Release it via
> dma_free_coherent.
> 
> Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-17  0:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15  1:10 [PATCH] net: gemini: Fix memory leak in gmac_setup_txqs Navid Emamdoost
2019-12-15 14:27 ` Markus Elfring
2019-12-16 10:20 ` Linus Walleij
2019-12-17  0:27 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).