* [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices
@ 2024-09-06 10:52 Tomas Paukrt
2024-09-06 12:39 ` Maxime Chevallier
2024-09-10 23:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Tomas Paukrt @ 2024-09-06 10:52 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Catalin Popescu,
Simon Horman
The probe() function is only used for DP83822 and DP83826 PHY,
leaving the private data pointer uninitialized for the DP83825 models
which causes a NULL pointer dereference in the recently introduced/changed
functions dp8382x_config_init() and dp83822_set_wol().
Add the dp8382x_probe() function, so all PHY models will have a valid
private data pointer to fix this issue and also prevent similar issues
in the future.
Fixes: 9ef9ecfa9e9f ("net: phy: dp8382x: keep WOL settings across suspends")
Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
---
Changes since v1:
- Reused the newly introduced function in dp83822_probe() and dp83826_probe()
---
drivers/net/phy/dp83822.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c
index efeb643..fc247f4 100644
--- a/drivers/net/phy/dp83822.c
+++ b/drivers/net/phy/dp83822.c
@@ -271,8 +271,7 @@ static int dp83822_config_intr(struct phy_device *phydev)
DP83822_ENERGY_DET_INT_EN |
DP83822_LINK_QUAL_INT_EN);
- /* Private data pointer is NULL on DP83825 */
- if (!dp83822 || !dp83822->fx_enabled)
+ if (!dp83822->fx_enabled)
misr_status |= DP83822_ANEG_COMPLETE_INT_EN |
DP83822_DUP_MODE_CHANGE_INT_EN |
DP83822_SPEED_CHANGED_INT_EN;
@@ -292,8 +291,7 @@ static int dp83822_config_intr(struct phy_device *phydev)
DP83822_PAGE_RX_INT_EN |
DP83822_EEE_ERROR_CHANGE_INT_EN);
- /* Private data pointer is NULL on DP83825 */
- if (!dp83822 || !dp83822->fx_enabled)
+ if (!dp83822->fx_enabled)
misr_status |= DP83822_ANEG_ERR_INT_EN |
DP83822_WOL_PKT_INT_EN;
@@ -691,10 +689,9 @@ static int dp83822_read_straps(struct phy_device *phydev)
return 0;
}
-static int dp83822_probe(struct phy_device *phydev)
+static int dp8382x_probe(struct phy_device *phydev)
{
struct dp83822_private *dp83822;
- int ret;
dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822),
GFP_KERNEL);
@@ -703,6 +700,20 @@ static int dp83822_probe(struct phy_device *phydev)
phydev->priv = dp83822;
+ return 0;
+}
+
+static int dp83822_probe(struct phy_device *phydev)
+{
+ struct dp83822_private *dp83822;
+ int ret;
+
+ ret = dp8382x_probe(phydev);
+ if (ret)
+ return ret;
+
+ dp83822 = phydev->priv;
+
ret = dp83822_read_straps(phydev);
if (ret)
return ret;
@@ -717,14 +728,11 @@ static int dp83822_probe(struct phy_device *phydev)
static int dp83826_probe(struct phy_device *phydev)
{
- struct dp83822_private *dp83822;
-
- dp83822 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83822),
- GFP_KERNEL);
- if (!dp83822)
- return -ENOMEM;
+ int ret;
- phydev->priv = dp83822;
+ ret = dp8382x_probe(phydev);
+ if (ret)
+ return ret;
dp83826_of_init(phydev);
@@ -795,6 +803,7 @@ static int dp83822_resume(struct phy_device *phydev)
PHY_ID_MATCH_MODEL(_id), \
.name = (_name), \
/* PHY_BASIC_FEATURES */ \
+ .probe = dp8382x_probe, \
.soft_reset = dp83822_phy_reset, \
.config_init = dp8382x_config_init, \
.get_wol = dp83822_get_wol, \
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices
2024-09-06 10:52 [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices Tomas Paukrt
@ 2024-09-06 12:39 ` Maxime Chevallier
2024-09-10 23:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Maxime Chevallier @ 2024-09-06 12:39 UTC (permalink / raw)
To: Tomas Paukrt
Cc: netdev, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Catalin Popescu, Simon Horman
On Fri, 06 Sep 2024 12:52:40 +0200 (CEST)
"Tomas Paukrt" <tomaspaukrt@email.cz> wrote:
> The probe() function is only used for DP83822 and DP83826 PHY,
> leaving the private data pointer uninitialized for the DP83825 models
> which causes a NULL pointer dereference in the recently introduced/changed
> functions dp8382x_config_init() and dp83822_set_wol().
>
> Add the dp8382x_probe() function, so all PHY models will have a valid
> private data pointer to fix this issue and also prevent similar issues
> in the future.
>
> Fixes: 9ef9ecfa9e9f ("net: phy: dp8382x: keep WOL settings across suspends")
> Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
That looks OK to me. Note that you must wait 24h between iterations,
to give everyone a chance to review.
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Thanks,
Maxime
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices
2024-09-06 10:52 [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices Tomas Paukrt
2024-09-06 12:39 ` Maxime Chevallier
@ 2024-09-10 23:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-09-10 23:30 UTC (permalink / raw)
To: Tomas Paukrt
Cc: netdev, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
catalin.popescu, horms
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 06 Sep 2024 12:52:40 +0200 (CEST) you wrote:
> The probe() function is only used for DP83822 and DP83826 PHY,
> leaving the private data pointer uninitialized for the DP83825 models
> which causes a NULL pointer dereference in the recently introduced/changed
> functions dp8382x_config_init() and dp83822_set_wol().
>
> Add the dp8382x_probe() function, so all PHY models will have a valid
> private data pointer to fix this issue and also prevent similar issues
> in the future.
>
> [...]
Here is the summary with links:
- [net,v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices
https://git.kernel.org/netdev/net/c/3f62ea572b3e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-10 23:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 10:52 [PATCH net v2] net: phy: dp83822: Fix NULL pointer dereference on DP83825 devices Tomas Paukrt
2024-09-06 12:39 ` Maxime Chevallier
2024-09-10 23:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox