diff mbox series

[net-next,1/2] net: mdio: of: fix potential NULL pointer derefernce

Message ID 20200130174451.17951-1-michael@walle.cc
State Accepted
Delegated to: David Miller
Headers show
Series [net-next,1/2] net: mdio: of: fix potential NULL pointer derefernce | expand

Commit Message

Michael Walle Jan. 30, 2020, 5:44 p.m. UTC
of_find_mii_timestamper() returns NULL if no timestamper is found.
Therefore, guard the unregister_mii_timestamper() calls.

Fixes: 1dca22b18421 ("net: mdio: of: Register discovered MII time stampers.")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/of/of_mdio.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Richard Cochran Jan. 31, 2020, 5:17 a.m. UTC | #1
On Thu, Jan 30, 2020 at 06:44:50PM +0100, Michael Walle wrote:
> of_find_mii_timestamper() returns NULL if no timestamper is found.
> Therefore, guard the unregister_mii_timestamper() calls.
> 
> Fixes: 1dca22b18421 ("net: mdio: of: Register discovered MII time stampers.")
> Signed-off-by: Michael Walle <michael@walle.cc>

Good catch.

Acked-by: Richard Cochran <richardcochran@gmail.com>
Jakub Kicinski Jan. 31, 2020, 3:49 p.m. UTC | #2
On Thu, 30 Jan 2020 18:44:50 +0100, Michael Walle wrote:
> of_find_mii_timestamper() returns NULL if no timestamper is found.
> Therefore, guard the unregister_mii_timestamper() calls.
> 
> Fixes: 1dca22b18421 ("net: mdio: of: Register discovered MII time stampers.")
> Signed-off-by: Michael Walle <michael@walle.cc>

Applied both, thank you.
Michael Walle Feb. 2, 2020, 8:13 p.m. UTC | #3
Hi Jakub,

Am 2020-01-31 16:49, schrieb Jakub Kicinski:
> On Thu, 30 Jan 2020 18:44:50 +0100, Michael Walle wrote:
>> of_find_mii_timestamper() returns NULL if no timestamper is found.
>> Therefore, guard the unregister_mii_timestamper() calls.
>> 
>> Fixes: 1dca22b18421 ("net: mdio: of: Register discovered MII time 
>> stampers.")
>> Signed-off-by: Michael Walle <michael@walle.cc>
> 
> Applied both, thank you.

Just for completeness, the subject should have to be [PATCH net], 
because its a fix, correct?

-michael
Jakub Kicinski Feb. 2, 2020, 8:22 p.m. UTC | #4
On Sun, 02 Feb 2020 21:13:53 +0100, Michael Walle wrote:
> Am 2020-01-31 16:49, schrieb Jakub Kicinski:
> > On Thu, 30 Jan 2020 18:44:50 +0100, Michael Walle wrote:  
> >> of_find_mii_timestamper() returns NULL if no timestamper is found.
> >> Therefore, guard the unregister_mii_timestamper() calls.
> >> 
> >> Fixes: 1dca22b18421 ("net: mdio: of: Register discovered MII time 
> >> stampers.")
> >> Signed-off-by: Michael Walle <michael@walle.cc>  
> > 
> > Applied both, thank you.  
> 
> Just for completeness, the subject should have to be [PATCH net], 
> because its a fix, correct?

Yup.
diff mbox series

Patch

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index f5c2a5487761..db0ed5879803 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -81,13 +81,15 @@  static int of_mdiobus_register_phy(struct mii_bus *mdio,
 	else
 		phy = get_phy_device(mdio, addr, is_c45);
 	if (IS_ERR(phy)) {
-		unregister_mii_timestamper(mii_ts);
+		if (mii_ts)
+			unregister_mii_timestamper(mii_ts);
 		return PTR_ERR(phy);
 	}
 
 	rc = of_irq_get(child, 0);
 	if (rc == -EPROBE_DEFER) {
-		unregister_mii_timestamper(mii_ts);
+		if (mii_ts)
+			unregister_mii_timestamper(mii_ts);
 		phy_device_free(phy);
 		return rc;
 	}
@@ -116,7 +118,8 @@  static int of_mdiobus_register_phy(struct mii_bus *mdio,
 	 * register it */
 	rc = phy_device_register(phy);
 	if (rc) {
-		unregister_mii_timestamper(mii_ts);
+		if (mii_ts)
+			unregister_mii_timestamper(mii_ts);
 		phy_device_free(phy);
 		of_node_put(child);
 		return rc;