net: phy: sfp: Fix unregistering of HWMON SFP device
authorAndrew Lunn <andrew@lunn.ch>
Mon, 24 Sep 2018 23:50:00 +0000 (01:50 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Sep 2018 03:23:31 +0000 (20:23 -0700)
A HWMON device is only registered is the SFP module supports the
diagnostic page and is complient to SFF8472. Don't unconditionally
unregister the hwmon device when the SFP module is remove, otherwise
we access data structures which don't exist.

Reported-by: Florian Fainelli <f.fainelli@gmail.com>
Fixes: 1323061a018a ("net: phy: sfp: Add HWMON support for module sensors")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/sfp.c

index 52fffb98fde9ac3fd05c7f6fd8e5dc123ecae341..6e13b8832bc7df94467211f07c1e7dba15a6e877 100644 (file)
@@ -1098,8 +1098,11 @@ static int sfp_hwmon_insert(struct sfp *sfp)
 
 static void sfp_hwmon_remove(struct sfp *sfp)
 {
-       hwmon_device_unregister(sfp->hwmon_dev);
-       kfree(sfp->hwmon_name);
+       if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) {
+               hwmon_device_unregister(sfp->hwmon_dev);
+               sfp->hwmon_dev = NULL;
+               kfree(sfp->hwmon_name);
+       }
 }
 #else
 static int sfp_hwmon_insert(struct sfp *sfp)