FAILED: patch "[PATCH] dpaa2-eth: Fix device reference count leak in MAC endpoint" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x ee9f3a81ab08dfe0538dbd1746f81fd4d5147fdc
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025072840-quickstep-spiny-0e80@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ee9f3a81ab08dfe0538dbd1746f81fd4d5147fdc Mon Sep 17 00:00:00 2001
From: Ma Ke <[email protected]>
Date: Thu, 17 Jul 2025 10:23:08 +0800
Subject: [PATCH] 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.
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +12 -3
@@ -4666,12 +4666,19 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)return PTR_ERR (dpmac_dev); } -if (IS_ERR (dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) +if (IS_ERR (dpmac_dev))return 0 ; +if (dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) { + err =0 ; + goto out_put_device; + } + mac =kzalloc (sizeof (struct dpaa2_mac ),GFP_KERNEL ); -if (!mac) -return -ENOMEM ; +if (!mac) { + err = -ENOMEM ; + goto out_put_device; + } mac->mc_dev = dpmac_dev; mac->mc_io = priv->mc_io;
@@ -4705,6 +4712,8 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)dpaa2_mac_close (mac); err_free_mac:kfree (mac); +out_put_device: +put_device (&dpmac_dev->dev);return err; }
Sasha Levin
maintainerPATCH 1/4 dpaa2-mac: split up initializing the MAC object from connecting to it
From: Ioana Ciornei <[email protected]>
[ Upstream commit 095dca16d92f32150314ef47ea150ed83c5aacd9 ]
Split up the initialization phase of the dpmac object from actually configuring the phylink instance, connecting to it and configuring the MAC. This is done so that even though the dpni object is connected to a dpmac which has link management handled by the firmware we are still able to export the MAC counters.
Stable-dep-of: ee9f3a81ab08 ("dpaa2-eth: Fix device reference count leak in MAC endpoint handling")
--- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 14 +++- .../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 69 +++++++++++-------- .../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 5 ++ 3 files changed, 59 insertions(+), 29 deletions(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +12 -2
@@ -4148,15 +4148,24 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) mac->mc_io = priv->mc_io; mac->net_dev = priv->net_dev; + err =dpaa2_mac_open (mac); +if (err) + goto err_free_mac; + err =dpaa2_mac_connect (mac);if (err) {netdev_err (priv->net_dev,"Error connecting to the MAC endpoint\n" ); -kfree (mac); -return err; + goto err_close_mac; } priv->mac = mac;return 0 ; + +err_close_mac: +dpaa2_mac_close (mac); +err_free_mac: +kfree (mac); +return err; }static void dpaa2_eth_disconnect_mac (struct dpaa2_eth_priv *priv)
@@ -4165,6 +4174,7 @@ static void dpaa2_eth_disconnect_mac(struct dpaa2_eth_priv *priv)return ;dpaa2_mac_disconnect (priv->mac); +dpaa2_mac_close (priv->mac);kfree (priv->mac); priv->mac =NULL ; }
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +42 -27
103 lines not on this page · raw message
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h +5 -0
@@ -17,6 +17,7 @@ struct dpaa2_mac {struct dpmac_link_state state;struct net_device *net_dev;struct fsl_mc_io *mc_io; +struct dpmac_attr attr;struct phylink_config phylink_config;struct phylink *phylink;
@@ -28,6 +29,10 @@ struct dpaa2_mac {bool dpaa2_mac_is_type_fixed (struct fsl_mc_device *dpmac_dev,struct fsl_mc_io *mc_io); +int dpaa2_mac_open (struct dpaa2_mac *mac); + +void dpaa2_mac_close (struct dpaa2_mac *mac); +int dpaa2_mac_connect (struct dpaa2_mac *mac);void dpaa2_mac_disconnect (struct dpaa2_mac *mac);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 2/4 dpaa2-mac: export MAC counters even when in TYPE_FIXED
From: Ioana Ciornei <[email protected]>
[ Upstream commit d87e606373f641c58d5e8e4c48b3216fd9d1c78a ]
If the network interface object is connected to a MAC of TYPE_FIXED, the link status management is handled exclusively by the firmware. This does not mean that the driver cannot access the MAC counters and export them in ethtool.
For this to happen, we open the attached dpmac device and keep a pointer to it in priv->mac. Because of this, all the checks in the driver of the following form 'if (priv->mac)' have to be updated to actually check the dpmac attribute and not rely on the presence of a non-NULL value.
Stable-dep-of: ee9f3a81ab08 ("dpaa2-eth: Fix device reference count leak in MAC endpoint handling")
--- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 37 +++++++++---------- .../net/ethernet/freescale/dpaa2/dpaa2-eth.h | 13 +++++++ .../ethernet/freescale/dpaa2/dpaa2-ethtool.c | 16 ++++---- .../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 26 ------------- 4 files changed, 39 insertions(+), 53 deletions(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +18 -19
@@ -1765,7 +1765,7 @@ static int dpaa2_eth_link_state_update(struct dpaa2_eth_priv *priv)/* When we manage the MAC/PHY using phylink there is no need * to manually update the netif_carrier. */ -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv)) goto out;/* Chech link state; speed / duplex changes are not treated yet */
@@ -1804,7 +1804,7 @@ static int dpaa2_eth_open(struct net_device *net_dev) priv->dpbp_dev->obj_desc.id, priv->bpid); } -if (!priv->mac) { +if (!dpaa2_eth_is_type_phy (priv)) {/* We'll only start the txqs when the link is actually ready; * make sure we don't race against the link up notification, * which may come immediately after dpni_enable();
@@ -1826,7 +1826,7 @@ static int dpaa2_eth_open(struct net_device *net_dev) goto enable_err; } -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv))phylink_start (priv->mac->phylink);return 0 ;
@@ -1900,11 +1900,11 @@ static int dpaa2_eth_stop(struct net_device *net_dev)int dpni_enabled =0 ;int retries =10 ; -if (!priv->mac) { +if (dpaa2_eth_is_type_phy (priv)) { +phylink_stop (priv->mac->phylink); + }else {netif_tx_stop_all_queues (net_dev);netif_carrier_off (net_dev); - }else { -phylink_stop (priv->mac->phylink); }/* On dpni_disable(), the MC firmware will:
@@ -2192,7 +2192,7 @@ static int dpaa2_eth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (cmd ==SIOCSHWTSTAMP )return dpaa2_eth_ts_ioctl (dev, rq, cmd); -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv))return phylink_mii_ioctl (priv->mac->phylink, rq, cmd);return -EOPNOTSUPP ;
@@ -4137,9 +4137,6 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)if (IS_ERR_OR_NULL (dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type)return 0 ; -if (dpaa2_mac_is_type_fixed (dpmac_dev, priv->mc_io)) -return 0 ; - mac =kzalloc (sizeof (struct dpaa2_mac ),GFP_KERNEL );if (!mac)return -ENOMEM ;
@@ -4151,18 +4148,21 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) err =dpaa2_mac_open (mac);if (err) goto err_free_mac; + priv->mac = mac; - err =dpaa2_mac_connect (mac); -if (err) { -netdev_err (priv->net_dev,"Error connecting to the MAC endpoint\n" ); - goto err_close_mac; +if (dpaa2_eth_is_type_phy (priv)) { + err =dpaa2_mac_connect (mac); +if (err) { +netdev_err (priv->net_dev,"Error connecting to the MAC endpoint\n" ); + goto err_close_mac; + } } - priv->mac = mac;return 0 ; err_close_mac:dpaa2_mac_close (mac); + priv->mac =NULL ; err_free_mac:kfree (mac);return err;
@@ -4170,10 +4170,9 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)static void dpaa2_eth_disconnect_mac (struct dpaa2_eth_priv *priv) { -if (!priv->mac) -return ; +if (dpaa2_eth_is_type_phy (priv)) +dpaa2_mac_disconnect (priv->mac); -dpaa2_mac_disconnect (priv->mac);dpaa2_mac_close (priv->mac);kfree (priv->mac); priv->mac =NULL ;
@@ -4203,7 +4202,7 @@ static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)dpaa2_eth_update_tx_fqids (priv);rtnl_lock (); -if (priv->mac) +if (dpaa2_eth_has_mac (priv))dpaa2_eth_disconnect_mac (priv);else dpaa2_eth_connect_mac (priv);
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h +13 -0
@@ -705,6 +705,19 @@ static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv)return priv->tx_data_offset -DPAA2_ETH_RX_HWA_SIZE ; } +static inline bool dpaa2_eth_is_type_phy (struct dpaa2_eth_priv *priv) +{ +if (priv->mac && priv->mac->attr.link_type ==DPMAC_LINK_TYPE_PHY ) +return true; + +return false; +} + +static inline bool dpaa2_eth_has_mac (struct dpaa2_eth_priv *priv) +{ +return priv->mac ? true : false; +} +int dpaa2_eth_set_hash (struct net_device *net_dev,u64 flags);int dpaa2_eth_set_cls (struct net_device *net_dev,u64 key);int dpaa2_eth_cls_key_size (u64 key);
drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c +8 -8
@@ -85,7 +85,7 @@ static int dpaa2_eth_nway_reset(struct net_device *net_dev) {struct dpaa2_eth_priv *priv =netdev_priv (net_dev); -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv))return phylink_ethtool_nway_reset (priv->mac->phylink);return -EOPNOTSUPP ;
@@ -97,7 +97,7 @@ dpaa2_eth_get_link_ksettings(struct net_device *net_dev, {struct dpaa2_eth_priv *priv =netdev_priv (net_dev); -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv))return phylink_ethtool_ksettings_get (priv->mac->phylink, link_settings);
@@ -115,7 +115,7 @@ dpaa2_eth_set_link_ksettings(struct net_device *net_dev, {struct dpaa2_eth_priv *priv =netdev_priv (net_dev); -if (!priv->mac) +if (!dpaa2_eth_is_type_phy (priv))return -ENOTSUPP ;return phylink_ethtool_ksettings_set (priv->mac->phylink, link_settings);
@@ -127,7 +127,7 @@ static void dpaa2_eth_get_pauseparam(struct net_device *net_dev,struct dpaa2_eth_priv *priv =netdev_priv (net_dev);u64 link_options = priv->link_state.options; -if (priv->mac) { +if (dpaa2_eth_is_type_phy (priv)) {phylink_ethtool_get_pauseparam (priv->mac->phylink, pause);return ; }
@@ -150,7 +150,7 @@ static int dpaa2_eth_set_pauseparam(struct net_device *net_dev,return -EOPNOTSUPP ; } -if (priv->mac) +if (dpaa2_eth_is_type_phy (priv))return phylink_ethtool_set_pauseparam (priv->mac->phylink, pause);if (pause->autoneg)
@@ -198,7 +198,7 @@ static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset,strlcpy (p, dpaa2_ethtool_extras[i],ETH_GSTRING_LEN ); p +=ETH_GSTRING_LEN ; } -if (priv->mac) +if (dpaa2_eth_has_mac (priv))dpaa2_mac_get_strings (p);break ; }
@@ -211,7 +211,7 @@ static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset)switch (sset) {case ETH_SS_STATS :/* ethtool_get_stats(), ethtool_get_drvinfo() */ -if (priv->mac) +if (dpaa2_eth_has_mac (priv)) num_ss_stats +=dpaa2_mac_get_sset_count ();return num_ss_stats;default :
@@ -311,7 +311,7 @@ static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev, } *(data + i++) = buf_cnt; -if (priv->mac) +if (dpaa2_eth_has_mac (priv))dpaa2_mac_get_ethtool_stats (priv->mac, data + i); }
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +0 -26
@@ -228,32 +228,6 @@ static const struct phylink_mac_ops dpaa2_mac_phylink_ops = { .mac_link_down = dpaa2_mac_link_down, }; -bool dpaa2_mac_is_type_fixed (struct fsl_mc_device *dpmac_dev, -struct fsl_mc_io *mc_io) -{ -struct dpmac_attr attr; -bool fixed = false; -u16 mc_handle =0 ; -int err; - - err =dpmac_open (mc_io,0 , dpmac_dev->obj_desc.id, - &mc_handle); -if (err || !mc_handle) -return false; - - err =dpmac_get_attributes (mc_io,0 , mc_handle, &attr); -if (err) - goto out; - -if (attr.link_type ==DPMAC_LINK_TYPE_FIXED ) - fixed = true; - -out: -dpmac_close (mc_io,0 , mc_handle); - -return fixed; -} -static int dpaa2_pcs_create (struct dpaa2_mac *mac,struct device_node *dpmac_node,int id) {
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 3/4 dpaa2-eth: retry the probe when the MAC is not yet discovered on the bus
In reply to Sasha LevinFrom: Ioana Ciornei <[email protected]>
[ Upstream commit 47325da28ef137fa04a0e5d6d244e9635184bf5e ]
The fsl_mc_get_endpoint() function now returns -EPROBE_DEFER when the dpmac device was not yet discovered by the fsl-mc bus. When this happens, pass the error code up so that we can retry the probe at a later time.
Stable-dep-of: ee9f3a81ab08 ("dpaa2-eth: Fix device reference count leak in MAC endpoint handling")
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +5 -1
@@ -4134,7 +4134,11 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) dpni_dev =to_fsl_mc_device (priv->net_dev->dev.parent); dpmac_dev =fsl_mc_get_endpoint (dpni_dev); -if (IS_ERR_OR_NULL (dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) + +if (PTR_ERR (dpmac_dev) == -EPROBE_DEFER ) +return PTR_ERR (dpmac_dev); + +if (IS_ERR (dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type)return 0 ; mac =kzalloc (sizeof (struct dpaa2_mac ),GFP_KERNEL );
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 4/4 dpaa2-eth: Fix device reference count leak in MAC endpoint handling
In reply to Sasha LevinFrom: Ma Ke <[email protected]>
[ Upstream commit ee9f3a81ab08dfe0538dbd1746f81fd4d5147fdc ]
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.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +12 -3
@@ -4138,12 +4138,19 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv)if (PTR_ERR (dpmac_dev) == -EPROBE_DEFER )return PTR_ERR (dpmac_dev); -if (IS_ERR (dpmac_dev) || dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) +if (IS_ERR (dpmac_dev))return 0 ; +if (dpmac_dev->dev.type != &fsl_mc_bus_dpmac_type) { + err =0 ; + goto out_put_device; + } + mac =kzalloc (sizeof (struct dpaa2_mac ),GFP_KERNEL ); -if (!mac) -return -ENOMEM ; +if (!mac) { + err = -ENOMEM ; + goto out_put_device; + } mac->mc_dev = dpmac_dev; mac->mc_io = priv->mc_io;
@@ -4169,6 +4176,8 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) priv->mac =NULL ; err_free_mac:kfree (mac); +out_put_device: +put_device (&dpmac_dev->dev);return err; }
Signature · 1 line
2.39.5