Message ID | 20240523062920.2472432-1-xiaolei.wang@windriver.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] net: fec: free fec queue when fec_probe() fails or fec_drv_remove() | expand |
On Thu, May 23, 2024 at 02:29:20PM +0800, Xiaolei Wang wrote: > commit 59d0f7465644 ("net: fec: init multi queue date structure") > allocates multiple queues, which should be cleaned up when fec_probe() > fails or fec_drv_remove(), otherwise a memory leak will occur. > > unreferenced object 0xffffff8010350000 (size 8192): > comm "kworker/u8:3", pid 39, jiffies 4294893562 > hex dump (first 32 bytes): > 02 00 00 00 00 00 00 00 00 50 06 8a c0 ff ff ff .........P...... > e0 6f 06 8a c0 ff ff ff 00 50 06 8a c0 ff ff ff .o.......P...... > backtrace (crc f1b8b79f): > [<0000000057d2c6ae>] kmemleak_alloc+0x34/0x40 > [<000000003c413e60>] kmalloc_trace+0x2f8/0x460 > [<00000000663f64e6>] fec_probe+0x1364/0x3a04 > [<0000000024d7e427>] platform_probe+0xc4/0x198 > [<00000000293aa124>] really_probe+0x17c/0x4f0 > [<00000000dfd1e0f3>] __driver_probe_device+0x158/0x2c4 > > Fixes: 59d0f7465644 ("net: fec: init multi queue date structure") > Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> Please read what i suggested. It is good to have code which is symmetric. probe() and remove() should be opposites of each other. probe() calls fec_enet_init(). So it would be good to have remove() call fec_enet_deinit() which does the opposite. We then have symmetry. Is there anything else in fec_enet_init() which needs undoing? A rule of thumb: If you find a bug, look around, there might be others nearby. Maybe leaking the queues is not the only problem? Andrew
> -----Original Message----- > From: Xiaolei Wang <xiaolei.wang@windriver.com> > Sent: 2024年5月23日 14:29 > To: Wei Fang <wei.fang@nxp.com>; andrew@lunn.ch; Shenwei Wang > <shenwei.wang@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>; > davem@davemloft.net; edumazet@google.com; kuba@kernel.org; > pabeni@redhat.com > Cc: imx@lists.linux.dev; netdev@vger.kernel.org; > linux-kernel@vger.kernel.org > Subject: [v2 PATCH] net: fec: free fec queue when fec_probe() fails or > fec_drv_remove() > > commit 59d0f7465644 ("net: fec: init multi queue date structure") > allocates multiple queues, which should be cleaned up when fec_probe() > fails or fec_drv_remove(), otherwise a memory leak will occur. > > unreferenced object 0xffffff8010350000 (size 8192): > comm "kworker/u8:3", pid 39, jiffies 4294893562 > hex dump (first 32 bytes): > 02 00 00 00 00 00 00 00 00 50 06 8a c0 ff ff ff .........P...... > e0 6f 06 8a c0 ff ff ff 00 50 06 8a c0 ff ff ff .o.......P...... > backtrace (crc f1b8b79f): > [<0000000057d2c6ae>] kmemleak_alloc+0x34/0x40 > [<000000003c413e60>] kmalloc_trace+0x2f8/0x460 > [<00000000663f64e6>] fec_probe+0x1364/0x3a04 > [<0000000024d7e427>] platform_probe+0xc4/0x198 > [<00000000293aa124>] really_probe+0x17c/0x4f0 > [<00000000dfd1e0f3>] __driver_probe_device+0x158/0x2c4 > > Fixes: 59d0f7465644 ("net: fec: init multi queue date structure") > Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> > --- > v1 -> v2 > - Add fec_enet_free_queue() in fec_drv_remove() > > drivers/net/ethernet/freescale/fec_main.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/net/ethernet/freescale/fec_main.c > b/drivers/net/ethernet/freescale/fec_main.c > index a72d8a2eb0b3..775029af6042 100644 > --- a/drivers/net/ethernet/freescale/fec_main.c > +++ b/drivers/net/ethernet/freescale/fec_main.c > @@ -4524,6 +4524,7 @@ fec_probe(struct platform_device *pdev) > fec_enet_mii_remove(fep); > failed_mii_init: > failed_irq: > + fec_enet_free_queue(ndev); > failed_init: > fec_ptp_stop(pdev); > failed_reset: > @@ -4587,6 +4588,7 @@ fec_drv_remove(struct platform_device *pdev) > pm_runtime_put_noidle(&pdev->dev); > pm_runtime_disable(&pdev->dev); > > + fec_enet_free_queue(ndev); > free_netdev(ndev); > } > > -- > 2.25.1 Thanks! Reviewed-by: Wei Fang <wei.fang@nxp.com>
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index a72d8a2eb0b3..775029af6042 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -4524,6 +4524,7 @@ fec_probe(struct platform_device *pdev) fec_enet_mii_remove(fep); failed_mii_init: failed_irq: + fec_enet_free_queue(ndev); failed_init: fec_ptp_stop(pdev); failed_reset: @@ -4587,6 +4588,7 @@ fec_drv_remove(struct platform_device *pdev) pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev); + fec_enet_free_queue(ndev); free_netdev(ndev); }
commit 59d0f7465644 ("net: fec: init multi queue date structure") allocates multiple queues, which should be cleaned up when fec_probe() fails or fec_drv_remove(), otherwise a memory leak will occur. unreferenced object 0xffffff8010350000 (size 8192): comm "kworker/u8:3", pid 39, jiffies 4294893562 hex dump (first 32 bytes): 02 00 00 00 00 00 00 00 00 50 06 8a c0 ff ff ff .........P...... e0 6f 06 8a c0 ff ff ff 00 50 06 8a c0 ff ff ff .o.......P...... backtrace (crc f1b8b79f): [<0000000057d2c6ae>] kmemleak_alloc+0x34/0x40 [<000000003c413e60>] kmalloc_trace+0x2f8/0x460 [<00000000663f64e6>] fec_probe+0x1364/0x3a04 [<0000000024d7e427>] platform_probe+0xc4/0x198 [<00000000293aa124>] really_probe+0x17c/0x4f0 [<00000000dfd1e0f3>] __driver_probe_device+0x158/0x2c4 Fixes: 59d0f7465644 ("net: fec: init multi queue date structure") Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> --- v1 -> v2 - Add fec_enet_free_queue() in fec_drv_remove() drivers/net/ethernet/freescale/fec_main.c | 2 ++ 1 file changed, 2 insertions(+)