mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] wifi: mt76: mt7996: Add NULL check in mt7996_thermal_init
@ 2025-03-31 10:35 Henry Martin
  2025-03-31 11:13 ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Henry Martin @ 2025-03-31 10:35 UTC (permalink / raw)
  To: nbd, lorenzo, ryder.lee
  Cc: shayne.chen, sean.wang, matthias.bgg, angelogioacchino.delregno,
	howard-yh.hsu, StanleyYP.Wang, chui-hao.chiu, linux-wireless,
	linux-kernel, linux-arm-kernel, linux-mediatek, Henry Martin

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function mt7996_thermal_init.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

Fixes: 69d54ce7491d0 ("switch to single multi-radio wiphy")

Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index 6b660424aedc..702447022f0e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -217,6 +217,8 @@ static int mt7996_thermal_init(struct mt7996_phy *phy)
 
 	name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7996_%s.%d",
 			      wiphy_name(wiphy), phy->mt76->band_idx);
+	if (!name)
+		return -ENOMEM;
 	snprintf(cname, sizeof(cname), "cooling_device%d", phy->mt76->band_idx);
 
 	cdev = thermal_cooling_device_register(name, phy, &mt7996_thermal_ops);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wifi: mt76: mt7996: Add NULL check in mt7996_thermal_init
  2025-03-31 10:35 [PATCH] wifi: mt76: mt7996: Add NULL check in mt7996_thermal_init Henry Martin
@ 2025-03-31 11:13 ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-31 11:13 UTC (permalink / raw)
  To: Henry Martin, linux-wireless, linux-mediatek, linux-arm-kernel
  Cc: LKML, Angelo Gioacchino Del Regno, Felix Fietkau, Howard Hsu,
	Lorenzo Bianconi, Matthias Brugger, Peter Chiu, Ryder Lee,
	Sean Wang, Shayne Chen, StanleyYP Wang

> When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function mt7996_thermal_init.
>
> A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

* Please adhere to word wrapping preferences around 75 characters per text line.

* How do you think about to choose the imperative mood for an improved change description?
  https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n94

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] wifi: mt76: mt7996: Add NULL check in mt7996_thermal_init
@ 2025-04-07  9:55 Charles Han
  0 siblings, 0 replies; 3+ messages in thread
From: Charles Han @ 2025-04-07  9:55 UTC (permalink / raw)
  To: nbd, lorenzo, ryder.lee, shayne.chen, sean.wang, matthias.bgg,
	angelogioacchino.delregno, howard-yh.hsu, StanleyYP.Wang,
	chui-hao.chiu
  Cc: linux-wireless, linux-kernel, linux-arm-kernel, linux-mediatek,
	Charles Han

devm_kasprintf() can return a NULL pointer on failure,but this
returned value in mt7996_thermal_init() is not checked.
Add NULL check in mt7996_thermal_init(), to handle kernel NULL
pointer dereference error.

Fixes: 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
index 6b660424aedc..5af52bd1f1f1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -217,6 +217,9 @@ static int mt7996_thermal_init(struct mt7996_phy *phy)
 
 	name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7996_%s.%d",
 			      wiphy_name(wiphy), phy->mt76->band_idx);
+	if (!name)
+		return -ENOMEM;
+
 	snprintf(cname, sizeof(cname), "cooling_device%d", phy->mt76->band_idx);
 
 	cdev = thermal_cooling_device_register(name, phy, &mt7996_thermal_ops);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-07  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-31 10:35 [PATCH] wifi: mt76: mt7996: Add NULL check in mt7996_thermal_init Henry Martin
2025-03-31 11:13 ` Markus Elfring
2025-04-07  9:55 Charles Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®