netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: korina: free array used for rx/tx descriptors
@ 2020-10-11 11:39 Valentin Vidic
  2020-10-11 18:37 ` Willem de Bruijn
  0 siblings, 1 reply; 6+ messages in thread
From: Valentin Vidic @ 2020-10-11 11:39 UTC (permalink / raw)
  To: David S. Miller
  Cc: Philip Rischel, Felix Fietkau, Florian Fainelli, Roman Yeryomin,
	Jakub Kicinski, Andrew Morton, Mike Rapoport, Martin Habets,
	Michael S. Tsirkin, Valentin Vidic, netdev, linux-kernel

Memory was not freed when driver is unloaded from the kernel.

Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
 drivers/net/ethernet/korina.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index 03e034918d14..99146145f020 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -1133,6 +1133,7 @@ static int korina_remove(struct platform_device *pdev)
 	iounmap(lp->eth_regs);
 	iounmap(lp->rx_dma_regs);
 	iounmap(lp->tx_dma_regs);
+	kfree(lp->td_ring);
 
 	unregister_netdev(bif->dev);
 	free_netdev(bif->dev);
-- 
2.20.1


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

* Re: [PATCH] net: korina: free array used for rx/tx descriptors
  2020-10-11 11:39 [PATCH] net: korina: free array used for rx/tx descriptors Valentin Vidic
@ 2020-10-11 18:37 ` Willem de Bruijn
  2020-10-11 21:21   ` Valentin Vidić
  0 siblings, 1 reply; 6+ messages in thread
From: Willem de Bruijn @ 2020-10-11 18:37 UTC (permalink / raw)
  To: Valentin Vidic
  Cc: David S. Miller, Philip Rischel, Felix Fietkau, Florian Fainelli,
	Roman Yeryomin, Jakub Kicinski, Andrew Morton, Mike Rapoport,
	Martin Habets, Michael S. Tsirkin, Network Development,
	linux-kernel

On Sun, Oct 11, 2020 at 7:46 AM Valentin Vidic
<vvidic@valentin-vidic.from.hr> wrote:
>
> Memory was not freed when driver is unloaded from the kernel.
>
> Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>

Makes sense.

Fixes: ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")

Slightly off-topic, but I don't fully fathom what goes on with this
pointer straight after the initial kmalloc.

        lp->td_ring = (struct dma_desc *)KSEG1ADDR(lp->td_ring);

> ---
>  drivers/net/ethernet/korina.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
> index 03e034918d14..99146145f020 100644
> --- a/drivers/net/ethernet/korina.c
> +++ b/drivers/net/ethernet/korina.c
> @@ -1133,6 +1133,7 @@ static int korina_remove(struct platform_device *pdev)
>         iounmap(lp->eth_regs);
>         iounmap(lp->rx_dma_regs);
>         iounmap(lp->tx_dma_regs);
> +       kfree(lp->td_ring);
>
>         unregister_netdev(bif->dev);
>         free_netdev(bif->dev);

In general it is nice to release in reverse of acquire. But the driver
already does not follow this practice.

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

* Re: [PATCH] net: korina: free array used for rx/tx descriptors
  2020-10-11 18:37 ` Willem de Bruijn
@ 2020-10-11 21:21   ` Valentin Vidić
  2020-10-11 22:03     ` [PATCH v2] net: korina: fix kfree of rx/tx descriptor array Valentin Vidic
  0 siblings, 1 reply; 6+ messages in thread
From: Valentin Vidić @ 2020-10-11 21:21 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: David S. Miller, Philip Rischel, Florian Fainelli,
	Roman Yeryomin, Jakub Kicinski, Andrew Morton, Mike Rapoport,
	Martin Habets, Michael S. Tsirkin, Network Development,
	linux-kernel

On Sun, Oct 11, 2020 at 02:37:33PM -0400, Willem de Bruijn wrote:
> Slightly off-topic, but I don't fully fathom what goes on with this
> pointer straight after the initial kmalloc.
> 
>         lp->td_ring = (struct dma_desc *)KSEG1ADDR(lp->td_ring);

KSEG1ADDR should rewrite the memory address into the uncached region
for memory mapped I/O. Not sure if this would case problems for kfree
since there is another kfree on the fail path:

probe_err_register:
        kfree(lp->td_ring);

-- 
Valentin

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

* [PATCH v2] net: korina: fix kfree of rx/tx descriptor array
  2020-10-11 21:21   ` Valentin Vidić
@ 2020-10-11 22:03     ` Valentin Vidic
  2020-10-11 22:53       ` Willem de Bruijn
  0 siblings, 1 reply; 6+ messages in thread
From: Valentin Vidic @ 2020-10-11 22:03 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: David S. Miller, Philip Rischel, Florian Fainelli,
	Roman Yeryomin, Jakub Kicinski, Andrew Morton, Mike Rapoport,
	Martin Habets, Michael S. Tsirkin, Network Development,
	linux-kernel, Valentin Vidic

kmalloc returns KSEG0 addresses so convert back from KSEG1
in kfree. Also make sure array is freed when the driver is
unloaded from the kernel.

Fixes: ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
 v2: convert kfree address back to KSEG0

 drivers/net/ethernet/korina.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index 03e034918d14..af441d699a57 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -1113,7 +1113,7 @@ static int korina_probe(struct platform_device *pdev)
 	return rc;
 
 probe_err_register:
-	kfree(lp->td_ring);
+	kfree(KSEG0ADDR(lp->td_ring));
 probe_err_td_ring:
 	iounmap(lp->tx_dma_regs);
 probe_err_dma_tx:
@@ -1133,6 +1133,7 @@ static int korina_remove(struct platform_device *pdev)
 	iounmap(lp->eth_regs);
 	iounmap(lp->rx_dma_regs);
 	iounmap(lp->tx_dma_regs);
+	kfree(KSEG0ADDR(lp->td_ring));
 
 	unregister_netdev(bif->dev);
 	free_netdev(bif->dev);
-- 
2.20.1


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

* Re: [PATCH v2] net: korina: fix kfree of rx/tx descriptor array
  2020-10-11 22:03     ` [PATCH v2] net: korina: fix kfree of rx/tx descriptor array Valentin Vidic
@ 2020-10-11 22:53       ` Willem de Bruijn
  2020-10-12 17:07         ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Willem de Bruijn @ 2020-10-11 22:53 UTC (permalink / raw)
  To: Valentin Vidic
  Cc: Willem de Bruijn, David S. Miller, Philip Rischel,
	Florian Fainelli, Roman Yeryomin, Jakub Kicinski, Andrew Morton,
	Mike Rapoport, Martin Habets, Michael S. Tsirkin,
	Network Development, linux-kernel

On Sun, Oct 11, 2020 at 6:04 PM Valentin Vidic
<vvidic@valentin-vidic.from.hr> wrote:
>
> kmalloc returns KSEG0 addresses so convert back from KSEG1
> in kfree. Also make sure array is freed when the driver is
> unloaded from the kernel.
>
> Fixes: ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
> Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>

Ah, this a MIPS architecture feature, both KSEGs mapping the same
region, just cachable vs non-cachable.

Acked-by: Willem de Bruijn <willemb@google.com>


> ---
>  v2: convert kfree address back to KSEG0
>
>  drivers/net/ethernet/korina.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
> index 03e034918d14..af441d699a57 100644
> --- a/drivers/net/ethernet/korina.c
> +++ b/drivers/net/ethernet/korina.c
> @@ -1113,7 +1113,7 @@ static int korina_probe(struct platform_device *pdev)
>         return rc;
>
>  probe_err_register:
> -       kfree(lp->td_ring);
> +       kfree(KSEG0ADDR(lp->td_ring));
>  probe_err_td_ring:
>         iounmap(lp->tx_dma_regs);
>  probe_err_dma_tx:
> @@ -1133,6 +1133,7 @@ static int korina_remove(struct platform_device *pdev)
>         iounmap(lp->eth_regs);
>         iounmap(lp->rx_dma_regs);
>         iounmap(lp->tx_dma_regs);
> +       kfree(KSEG0ADDR(lp->td_ring));
>
>         unregister_netdev(bif->dev);
>         free_netdev(bif->dev);
> --
> 2.20.1
>

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

* Re: [PATCH v2] net: korina: fix kfree of rx/tx descriptor array
  2020-10-11 22:53       ` Willem de Bruijn
@ 2020-10-12 17:07         ` Jakub Kicinski
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2020-10-12 17:07 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: Valentin Vidic, David S. Miller, Philip Rischel,
	Florian Fainelli, Roman Yeryomin, Andrew Morton, Mike Rapoport,
	Martin Habets, Michael S. Tsirkin, Network Development,
	linux-kernel

On Sun, 11 Oct 2020 18:53:31 -0400 Willem de Bruijn wrote:
> On Sun, Oct 11, 2020 at 6:04 PM Valentin Vidic wrote:
> > kmalloc returns KSEG0 addresses so convert back from KSEG1
> > in kfree. Also make sure array is freed when the driver is
> > unloaded from the kernel.
> >
> > Fixes: ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
> > Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>  
> 
> Ah, this a MIPS architecture feature, both KSEGs mapping the same
> region, just cachable vs non-cachable.
> 
> Acked-by: Willem de Bruijn <willemb@google.com>

Applied, thank you!

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

end of thread, other threads:[~2020-10-12 17:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 11:39 [PATCH] net: korina: free array used for rx/tx descriptors Valentin Vidic
2020-10-11 18:37 ` Willem de Bruijn
2020-10-11 21:21   ` Valentin Vidić
2020-10-11 22:03     ` [PATCH v2] net: korina: fix kfree of rx/tx descriptor array Valentin Vidic
2020-10-11 22:53       ` Willem de Bruijn
2020-10-12 17:07         ` Jakub Kicinski

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).