Skip to content

Commit ad5c318

Browse files
joehattorikuba-moo
authored andcommitted
net: mv643xx_eth: fix an OF node reference leak
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]>
1 parent fb3a9a1 commit ad5c318

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
@@ -2704,9 +2704,15 @@ static struct platform_device *port_platdev[3];
27042704

27052705
static void mv643xx_eth_shared_of_remove(void)
27062706
{
2707+
struct mv643xx_eth_platform_data *pd;
27072708
int n;
27082709

27092710
for (n = 0; n < 3; n++) {
2711+
if (!port_platdev[n])
2712+
continue;
2713+
pd = dev_get_platdata(&port_platdev[n]->dev);
2714+
if (pd)
2715+
of_node_put(pd->phy_node);
27102716
platform_device_del(port_platdev[n]);
27112717
port_platdev[n] = NULL;
27122718
}
@@ -2769,8 +2775,10 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
27692775
}
27702776

27712777
ppdev = platform_device_alloc(MV643XX_ETH_NAME, dev_num);
2772-
if (!ppdev)
2773-
return -ENOMEM;
2778+
if (!ppdev) {
2779+
ret = -ENOMEM;
2780+
goto put_err;
2781+
}
27742782
ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
27752783
ppdev->dev.of_node = pnp;
27762784

@@ -2792,6 +2800,8 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
27922800

27932801
port_err:
27942802
platform_device_put(ppdev);
2803+
put_err:
2804+
of_node_put(ppd.phy_node);
27952805
return ret;
27962806
}
27972807

0 commit comments

Comments
 (0)