Skip to content

Commit 313474b

Browse files
joehattorigregkh
authored andcommitted
net: mv643xx_eth: fix an OF node reference leak
[ Upstream commit ad5c318 ] Current implementation of mv643xx_eth_shared_of_add_port() calls of_parse_phandle(), but does not release the refcount on error. Call of_node_put() in the error path and in mv643xx_eth_shared_of_remove(). This bug was found by an experimental verification tool that I am developing. Fixes: 76723bc ("net: mv643xx_eth: add DT parsing support") Signed-off-by: Joe Hattori <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d5ea3a4 commit 313474b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/net/ethernet/marvell/mv643xx_eth.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,9 +2708,15 @@ static struct platform_device *port_platdev[3];
27082708

27092709
static void mv643xx_eth_shared_of_remove(void)
27102710
{
2711+
struct mv643xx_eth_platform_data *pd;
27112712
int n;
27122713

27132714
for (n = 0; n < 3; n++) {
2715+
if (!port_platdev[n])
2716+
continue;
2717+
pd = dev_get_platdata(&port_platdev[n]->dev);
2718+
if (pd)
2719+
of_node_put(pd->phy_node);
27142720
platform_device_del(port_platdev[n]);
27152721
port_platdev[n] = NULL;
27162722
}
@@ -2773,8 +2779,10 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
27732779
}
27742780

27752781
ppdev = platform_device_alloc(MV643XX_ETH_NAME, dev_num);
2776-
if (!ppdev)
2777-
return -ENOMEM;
2782+
if (!ppdev) {
2783+
ret = -ENOMEM;
2784+
goto put_err;
2785+
}
27782786
ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
27792787
ppdev->dev.of_node = pnp;
27802788

@@ -2796,6 +2804,8 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
27962804

27972805
port_err:
27982806
platform_device_put(ppdev);
2807+
put_err:
2808+
of_node_put(ppd.phy_node);
27992809
return ret;
28002810
}
28012811

0 commit comments

Comments
 (0)