Skip to contentSkip to conversation

net: phy: nxp-tja11xx: cancel registration work on remove

PATCH Superseded Hongyan Xu 2 participants 4 messages Jul 28 – Jul 29

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Hongyan Xu

author
#0 lore raw

PATCH 1/1 net: phy: nxp-tja11xx: cancel registration work on remove

tja1102_p0_probe() schedules work to register the second port. The work uses the Port 0 private data and phydev. The private data is devm-allocated, but the driver did not cancel the work before detach.

Store the Port 0 private data in phydev->priv and add a remove callback. The callback waits for the registration work before devres can free it.

This issue was found by a static analysis tool.

---
 drivers/net/phy/nxp-tja11xx.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/phy/nxp-tja11xx.c +9 -0
index 07e94a247..68062a4c5 100644
@@ -620,6 +620,7 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 		return -ENOMEM;
 
 	priv->phydev = phydev;
+	phydev->priv = priv;
 	INIT_WORK(&priv->phy_register_work, tja1102_p1_register);
 
 	ret = tja11xx_hwmon_register(phydev, priv);
@@ -631,6 +632,13 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static void tja1102_p0_remove(struct phy_device *phydev)
+{
+	struct tja11xx_priv *priv = phydev->priv;
+
+	cancel_work_sync(&priv->phy_register_work);
+}
+
 static int tja1102_match_phy_device(struct phy_device *phydev, bool port0)
 {
 	int ret;
@@ -847,6 +855,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.flags          = PHY_POLL_CABLE_TEST,
 		.probe		= tja1102_p0_probe,
+		.remove		= tja1102_p0_remove,
 		.soft_reset	= tja11xx_soft_reset,
 		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
Signature · 1 line
2.50.1.windows.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hongyan Xu

tja1102_p0_probe() schedules work to register the second port. The work uses the Port 0 private data and phydev. The private data is devm-allocated, but the driver did not cancel the work before detach.

Store the Port 0 private data in phydev->priv and add a remove callback. The callback waits for the registration work before devres can free it.

This issue was found by a static analysis tool.

Please take a read of:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

The Subject: line should indicate which tree this patch should be applied to.

Andrew

author
#2 lore raw

PATCH v2 1/1 net: phy: nxp-tja11xx: cancel registration work on remove

In reply to Hongyan Xu

tja1102_p0_probe() schedules work to register the second port. That work uses the Port 0 private data and phydev. The private data is devm-allocated, but the driver does not cancel the work before detach.

If the device is removed before the worker runs, devres can free the private data while the pending work still dereferences it.

Store the Port 0 private data in phydev->priv and add a remove callback. The callback waits for the registration work before devres can free it.

This issue was found by a static analysis tool.

Fixes 6a64d3cdc5ef ("net: phy: tja11xx: add delayed registration of TJA1102 PHY1")

---
v2:
- mark the patch for the net tree as suggested by Andrew Lunn
- add the Fixes tag
- no code changes

 drivers/net/phy/nxp-tja11xx.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/phy/nxp-tja11xx.c +9 -0
index 07e94a247..68062a4c5 100644
@@ -620,6 +620,7 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 		return -ENOMEM;
 
 	priv->phydev = phydev;
+	phydev->priv = priv;
 	INIT_WORK(&priv->phy_register_work, tja1102_p1_register);
 
 	ret = tja11xx_hwmon_register(phydev, priv);
@@ -631,6 +632,13 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static void tja1102_p0_remove(struct phy_device *phydev)
+{
+	struct tja11xx_priv *priv = phydev->priv;
+
+	cancel_work_sync(&priv->phy_register_work);
+}
+
 static int tja1102_match_phy_device(struct phy_device *phydev, bool port0)
 {
 	int ret;
@@ -847,6 +855,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.flags          = PHY_POLL_CABLE_TEST,
 		.probe		= tja1102_p0_probe,
+		.remove		= tja1102_p0_remove,
 		.soft_reset	= tja11xx_soft_reset,
 		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
Signature · 1 line
2.50.1.windows.1
author
#3 lore raw

PATCH v3 1/1 net: phy: nxp-tja11xx: cancel registration work on remove

tja1102_p0_probe() schedules work to register the second port. That work uses the Port 0 private data and phydev. The private data is devm-allocated, but the driver does not wait for the pending work on remove.

Store the Port 0 private data in phydev->priv and add a remove callback. The callback cancels the registration work before devres teardown frees the state.

This issue was found by a static analysis tool.

---
v3:
- drop the Fixes tag
- target net-next instead of net
- no code changes

v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

 drivers/net/phy/nxp-tja11xx.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/phy/nxp-tja11xx.c +9 -0
index 07e94a247..68062a4c5 100644
@@ -620,6 +620,7 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 		return -ENOMEM;
 
 	priv->phydev = phydev;
+	phydev->priv = priv;
 	INIT_WORK(&priv->phy_register_work, tja1102_p1_register);
 
 	ret = tja11xx_hwmon_register(phydev, priv);
@@ -631,6 +632,13 @@ static int tja1102_p0_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static void tja1102_p0_remove(struct phy_device *phydev)
+{
+	struct tja11xx_priv *priv = phydev->priv;
+
+	cancel_work_sync(&priv->phy_register_work);
+}
+
 static int tja1102_match_phy_device(struct phy_device *phydev, bool port0)
 {
 	int ret;
@@ -847,6 +855,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.flags          = PHY_POLL_CABLE_TEST,
 		.probe		= tja1102_p0_probe,
+		.remove		= tja1102_p0_remove,
 		.soft_reset	= tja11xx_soft_reset,
 		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
Signature · 1 line
2.50.1.windows.1