Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

phy: lynx-28g: improve lynx_28g_probe() sequence

dev_set_drvdata() is called twice, it is sufficient to do it only once.

devm_of_phy_provider_register() can fail, and if it does, the
&priv->cdr_check work item is queued, but not cancelled, and the device
probing failed, so it will trigger use after free. This is a minor risk
though.

Resource initialization should be done a little earlier, in case we need
to dereference dev_get_drvdata() in lynx_28g_pll_read_configuration() or
in lynx_28g_lane_read_configuration().

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20251125114847.804961-16-vladimir.oltean@nxp.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Vladimir Oltean and committed by
Vinod Koul
aecea964 04dceaa3

+8 -8
+8 -8
drivers/phy/freescale/phy-fsl-lynx-28g.c
··· 1163 1163 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 1164 1164 if (!priv) 1165 1165 return -ENOMEM; 1166 + 1166 1167 priv->dev = dev; 1168 + dev_set_drvdata(dev, priv); 1169 + spin_lock_init(&priv->pcc_lock); 1170 + INIT_DELAYED_WORK(&priv->cdr_check, lynx_28g_cdr_lock_check); 1167 1171 1168 1172 priv->base = devm_platform_ioremap_resource(pdev, 0); 1169 1173 if (IS_ERR(priv->base)) ··· 1212 1208 } 1213 1209 } 1214 1210 1215 - dev_set_drvdata(dev, priv); 1216 - 1217 - spin_lock_init(&priv->pcc_lock); 1218 - INIT_DELAYED_WORK(&priv->cdr_check, lynx_28g_cdr_lock_check); 1211 + provider = devm_of_phy_provider_register(dev, lynx_28g_xlate); 1212 + if (IS_ERR(provider)) 1213 + return PTR_ERR(provider); 1219 1214 1220 1215 queue_delayed_work(system_power_efficient_wq, &priv->cdr_check, 1221 1216 msecs_to_jiffies(1000)); 1222 1217 1223 - dev_set_drvdata(dev, priv); 1224 - provider = devm_of_phy_provider_register(dev, lynx_28g_xlate); 1225 - 1226 - return PTR_ERR_OR_ZERO(provider); 1218 + return 0; 1227 1219 } 1228 1220 1229 1221 static void lynx_28g_remove(struct platform_device *pdev)