diff mbox series

[net-next,1/2] net: phy: micrel: Allow probing without .driver_data

Message ID 20220513114613.762810-1-festevam@gmail.com (mailing list archive)
State Accepted
Commit f2ef6f7539c68c6bd6c32323d8845ee102b7c450
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] net: phy: micrel: Allow probing without .driver_data | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: linux@armlinux.org.uk edumazet@google.com hkallweit1@gmail.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Fabio Estevam May 13, 2022, 11:46 a.m. UTC
From: Fabio Estevam <festevam@denx.de>

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>
---
 drivers/net/phy/micrel.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Andrew Lunn May 13, 2022, 7:36 p.m. UTC | #1
On Fri, May 13, 2022 at 08:46:12AM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <festevam@denx.de>
> 
> 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>

    Andrew
patchwork-bot+netdevbpf@kernel.org May 16, 2022, 8:10 p.m. UTC | #2
Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 13 May 2022 08:46:12 -0300 you wrote:
> From: Fabio Estevam <festevam@denx.de>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: phy: micrel: Allow probing without .driver_data
    https://git.kernel.org/netdev/net-next/c/f2ef6f7539c6
  - [net-next,2/2] net: phy: micrel: Use the kszphy probe/suspend/resume
    https://git.kernel.org/netdev/net-next/c/8e6004dfecb7

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index c34a93403d1e..5e356e23c1b7 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -520,7 +520,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;
@@ -536,10 +536,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);
@@ -1730,7 +1730,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)
@@ -1751,7 +1751,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");