Skip to content

Commit ee9f3a8

Browse files
Ma Kekuba-moo
authored andcommitted
dpaa2-eth: Fix device reference count leak in MAC endpoint handling
The fsl_mc_get_endpoint() function uses device_find_child() for localization, which implicitly calls get_device() to increment the device's reference count before returning the pointer. However, the caller dpaa2_eth_connect_mac() fails to properly release this reference in multiple scenarios. We should call put_device() to decrement reference count properly. As comment of device_find_child() says, 'NOTE: you will need to drop the reference with put_device() after use'. Found by code review. Cc: [email protected] Fixes: 7194792 ("dpaa2-eth: add MAC/PHY support through phylink") Signed-off-by: Ma Ke <[email protected]> Tested-by: Ioana Ciornei <[email protected]> Reviewed-by: Ioana Ciornei <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bddbe13 commit ee9f3a8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4666,12 +4666,19 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)
46664666
return PTR_ERR(dpmac_dev);
46674667
}
46684668

4669-
if (IS_ERR(dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type)
4669+
if (IS_ERR(dpmac_dev))
46704670
return 0;
46714671

4672+
if (dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) {
4673+
err = 0;
4674+
goto out_put_device;
4675+
}
4676+
46724677
mac = kzalloc(sizeof(struct dpaa2_mac), GFP_KERNEL);
4673-
if (!mac)
4674-
return -ENOMEM;
4678+
if (!mac) {
4679+
err = -ENOMEM;
4680+
goto out_put_device;
4681+
}
46754682

46764683
mac->mc_dev = dpmac_dev;
46774684
mac->mc_io = priv->mc_io;
@@ -4705,6 +4712,8 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)
47054712
dpaa2_mac_close(mac);
47064713
err_free_mac:
47074714
kfree(mac);
4715+
out_put_device:
4716+
put_device(&dpmac_dev->dev);
47084717
return err;
47094718
}
47104719

0 commit comments

Comments
 (0)