mt76: mt7615: fix hwmon temp sensor mem use-after-free
authorRyder Lee <ryder.lee@mediatek.com>
Thu, 2 Sep 2021 05:52:04 +0000 (13:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 18:16:37 +0000 (19:16 +0100)
[ Upstream commit 0bb4e9187ea4a59dc6658a62978deda0c0dc4b28 ]

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

Fixes: 109e505ad944 ("mt76: mt7615: add thermal sensor device support")
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireless/mediatek/mt76/mt7615/init.c

index 2f1ac644e018e4ff6426dffdbc65230ec6cb69f7..47f23ac905a3cd64b5ce0424f17a3934d1c83881 100644 (file)
@@ -49,12 +49,14 @@ int mt7615_thermal_init(struct mt7615_dev *dev)
 {
        struct wiphy *wiphy = mt76_hw(dev)->wiphy;
        struct device *hwmon;
+       const char *name;
 
        if (!IS_REACHABLE(CONFIG_HWMON))
                return 0;
 
-       hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev,
-                                                      wiphy_name(wiphy), dev,
+       name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7615_%s",
+                             wiphy_name(wiphy));
+       hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, dev,
                                                       mt7615_hwmon_groups);
        if (IS_ERR(hwmon))
                return PTR_ERR(hwmon);