2020-10-11 18:06:03

by Valentin Vidić

[permalink] [raw]
Subject: [PATCH] net: korina: free array used for rx/tx descriptors

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

Signed-off-by: Valentin Vidic <[email protected]>
---
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


2020-10-12 02:11:20

by Willem de Bruijn

[permalink] [raw]
Subject: Re: [PATCH] net: korina: free array used for rx/tx descriptors

On Sun, Oct 11, 2020 at 7:46 AM Valentin Vidic
<[email protected]> wrote:
>
> Memory was not freed when driver is unloaded from the kernel.
>
> Signed-off-by: Valentin Vidic <[email protected]>

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.

2020-10-12 02:16:20

by Valentin Vidić

[permalink] [raw]
Subject: Re: [PATCH] net: korina: free array used for rx/tx descriptors

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

2020-10-12 02:18:02

by Valentin Vidić

[permalink] [raw]
Subject: [PATCH v2] net: korina: fix kfree of rx/tx descriptor array

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 <[email protected]>
---
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

2020-10-12 02:19:54

by Willem de Bruijn

[permalink] [raw]
Subject: Re: [PATCH v2] net: korina: fix kfree of rx/tx descriptor array

On Sun, Oct 11, 2020 at 6:04 PM Valentin Vidic
<[email protected]> 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 <[email protected]>

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

Acked-by: Willem de Bruijn <[email protected]>


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

2020-10-12 17:09:46

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH v2] net: korina: fix kfree of rx/tx descriptor array

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 <[email protected]>
>
> Ah, this a MIPS architecture feature, both KSEGs mapping the same
> region, just cachable vs non-cachable.
>
> Acked-by: Willem de Bruijn <[email protected]>

Applied, thank you!