Skip to content

Commit 96e056f

Browse files
Ma Kekuba-moo
authored andcommitted
dpaa2-switch: 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_switch_port_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: 84cba72 ("dpaa2-switch: integrate the MAC endpoint support") 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 ee9f3a8 commit 96e056f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,19 @@ static int dpaa2_switch_port_connect_mac(struct ethsw_port_priv *port_priv)
14481448
if (PTR_ERR(dpmac_dev) == -EPROBE_DEFER)
14491449
return PTR_ERR(dpmac_dev);
14501450

1451-
if (IS_ERR(dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type)
1451+
if (IS_ERR(dpmac_dev))
14521452
return 0;
14531453

1454+
if (dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) {
1455+
err = 0;
1456+
goto out_put_device;
1457+
}
1458+
14541459
mac = kzalloc(sizeof(*mac), GFP_KERNEL);
1455-
if (!mac)
1456-
return -ENOMEM;
1460+
if (!mac) {
1461+
err = -ENOMEM;
1462+
goto out_put_device;
1463+
}
14571464

14581465
mac->mc_dev = dpmac_dev;
14591466
mac->mc_io = port_priv->ethsw_data->mc_io;
@@ -1483,6 +1490,8 @@ static int dpaa2_switch_port_connect_mac(struct ethsw_port_priv *port_priv)
14831490
dpaa2_mac_close(mac);
14841491
err_free_mac:
14851492
kfree(mac);
1493+
out_put_device:
1494+
put_device(&dpmac_dev->dev);
14861495
return err;
14871496
}
14881497

0 commit comments

Comments
 (0)