net: phy: sfp: Fix unregistering of HWMON SFP device

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: 1323061a01 ("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>
This commit is contained in:
Andrew Lunn 2018-09-25 01:50:00 +02:00 committed by David S. Miller
parent 77f2d75381
commit 3e32247448
1 changed files with 5 additions and 2 deletions

View File

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