Skip to content

Commit

Permalink
net: phy: micrel: Allow probing without .driver_data
Browse files Browse the repository at this point in the history
[ Upstream commit f2ef6f7 ]

Currently, if the .probe element is present in the phy_driver structure
and the .driver_data is not, a NULL pointer dereference happens.

Allow passing .probe without .driver_data by inserting NULL checks
for priv->type.

Signed-off-by: Fabio Estevam <festevam@denx.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20220513114613.762810-1-festevam@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Fabio Estevam authored and gregkh committed Jun 9, 2022
1 parent e9cdc88 commit 143878e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/net/phy/micrel.c
Expand Up @@ -348,7 +348,7 @@ static int kszphy_config_reset(struct phy_device *phydev)
}
}

if (priv->led_mode >= 0)
if (priv->type && priv->led_mode >= 0)
kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode);

return 0;
Expand All @@ -364,10 +364,10 @@ static int kszphy_config_init(struct phy_device *phydev)

type = priv->type;

if (type->has_broadcast_disable)
if (type && type->has_broadcast_disable)
kszphy_broadcast_disable(phydev);

if (type->has_nand_tree_disable)
if (type && type->has_nand_tree_disable)
kszphy_nand_tree_disable(phydev);

return kszphy_config_reset(phydev);
Expand Down Expand Up @@ -1365,7 +1365,7 @@ static int kszphy_probe(struct phy_device *phydev)

priv->type = type;

if (type->led_mode_reg) {
if (type && type->led_mode_reg) {
ret = of_property_read_u32(np, "micrel,led-mode",
&priv->led_mode);
if (ret)
Expand All @@ -1386,7 +1386,8 @@ static int kszphy_probe(struct phy_device *phydev)
unsigned long rate = clk_get_rate(clk);
bool rmii_ref_clk_sel_25_mhz;

priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel;
if (type)
priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel;
rmii_ref_clk_sel_25_mhz = of_property_read_bool(np,
"micrel,rmii-reference-clock-select-25-mhz");

Expand Down

0 comments on commit 143878e

Please sign in to comment.