diff mbox series

[v3] mt76: mt7915: Fix hwmon temp sensor mem use-after-free.

Message ID 20210730232115.3965-1-greearb@candelatech.com (mailing list archive)
State Superseded
Delegated to: Felix Fietkau
Headers show
Series [v3] mt76: mt7915: Fix hwmon temp sensor mem use-after-free. | expand

Commit Message

Ben Greear July 30, 2021, 11:21 p.m. UTC
From: Ben Greear <greearb@candelatech.com>

Without this change, garbage is seen in the hwmon name
and sensors output for mt7915 is garbled.

With the change:

mt7915-pci-1400
Adapter: PCI adapter
temp1:        +49.0°C

Fixes: d6938251bb5be8 (mt76: mt7915: add thermal sensor device support)
Signed-off-by: Ben Greear <greearb@candelatech.com>
---

v3:  Add 'fixes' tag to aid backports.

 drivers/net/wireless/mediatek/mt76/mt7915/init.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index 192e3e190ce1..e741c4f73d19 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -132,8 +132,16 @@  static int mt7915_thermal_init(struct mt7915_phy *phy)
 	struct wiphy *wiphy = phy->mt76->hw->wiphy;
 	struct thermal_cooling_device *cdev;
 	struct device *hwmon;
+	struct mt7915_dev *dev = phy->dev;
+	bool ext_phy = phy != &dev->phy;
+	const char *my_prefix;
 
-	cdev = thermal_cooling_device_register(wiphy_name(wiphy), phy,
+	if (ext_phy)
+		my_prefix = "mt7915_ext";
+	else
+		my_prefix = "mt7915";
+
+	cdev = thermal_cooling_device_register(my_prefix, phy,
 					       &mt7915_thermal_ops);
 	if (!IS_ERR(cdev)) {
 		if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj,
@@ -147,7 +155,7 @@  static int mt7915_thermal_init(struct mt7915_phy *phy)
 		return 0;
 
 	hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev,
-						       wiphy_name(wiphy), phy,
+						       my_prefix, phy,
 						       mt7915_hwmon_groups);
 	if (IS_ERR(hwmon))
 		return PTR_ERR(hwmon);