Skip to contentSkip to conversation

mt76: mt7915: check devm_kasprintf() returned value

PATCH RESEND In review Ma Ke 2 participants 2 messages Sep 3, 2024 – Sep 4, 2024

Subsystems (3)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH RESEND 1/1 mt76: mt7915: check devm_kasprintf() returned value

devm_kasprintf() can return a NULL pointer on failure but this returned value is not checked. Fix this lack and check the returned value.

Found by code review.

Fixes 6ae39b7c7ed4 ("wifi: mt76: mt7921: Support temp sensor")
---
 drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +2 -0
index a978f434dc5e..7bc3b4cd3592 100644
@@ -194,6 +194,8 @@ static int mt7915_thermal_init(struct mt7915_phy *phy)
 
 	name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7915_%s",
 			      wiphy_name(wiphy));
+	if (!name)
+		return -ENOMEM;
 
 	cdev = thermal_cooling_device_register(name, phy, &mt7915_thermal_ops);
 	if (!IS_ERR(cdev)) {
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ma Ke

devm_kasprintf() can return a NULL pointer on failure but this returned value is not checked. Fix this lack and check the returned value.

Found by code review.

Fixes 6ae39b7c7ed4 ("wifi: mt76: mt7921: Support temp sensor")
Quoted 17 lines
---
  drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +2 -0
index a978f434dc5e..7bc3b4cd3592 100644
@@ -194,6 +194,8 @@ static int mt7915_thermal_init(struct mt7915_phy *phy)
 
  	name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7915_%s",
  			      wiphy_name(wiphy));
+	if (!name)
+		return -ENOMEM;
 
  	cdev = thermal_cooling_device_register(name, phy, &mt7915_thermal_ops);
  	if (!IS_ERR(cdev)) {