diff mbox series

wifi: mt76: mt7915: fix memory leak in mt7915_rate_txpower_get

Message ID 2ea534ec17856f65237939f3d437aad37ddc7753.1672740921.git.lorenzo@kernel.org
State New
Headers show
Series wifi: mt76: mt7915: fix memory leak in mt7915_rate_txpower_get | expand

Commit Message

Lorenzo Bianconi Jan. 3, 2023, 10:15 a.m. UTC
Fix possible memory leak in mt7915_rate_txpower_get routine if
mt7915_mcu_get_txpower_sku() fails.

Fixes: e3296759f347 ("wifi: mt76: mt7915: enable per bandwidth power limit support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Lorenzo Bianconi Jan. 16, 2023, 12:16 p.m. UTC | #1
> Fix possible memory leak in mt7915_rate_txpower_get routine if
> mt7915_mcu_get_txpower_sku() fails.
> 
> Fixes: e3296759f347 ("wifi: mt76: mt7915: enable per bandwidth power limit support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> index fb46c2c1784f..4730508652af 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
> @@ -990,14 +990,14 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
>  	char *buf;
>  	u32 reg;
>  
> -	buf = kzalloc(sz, GFP_KERNEL);
> -	if (!buf)
> -		return -ENOMEM;
> -
>  	ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
>  	if (ret)
>  		return ret;
>  
> +	buf = kzalloc(sz, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
>  	/* Txpower propagation path: TMAC -> TXV -> BBP */
>  	len += scnprintf(buf + len, sz - len,
>  			 "\nPhy%d Tx power table (channel %d)\n",
> -- 
> 2.39.0
> 

Felix,

It seems there is already a fix for it in your tree so we can drop this patch.

Regards,
Lorenzo
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index fb46c2c1784f..4730508652af 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -990,14 +990,14 @@  mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
 	char *buf;
 	u32 reg;
 
-	buf = kzalloc(sz, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
 	ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
 	if (ret)
 		return ret;
 
+	buf = kzalloc(sz, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
 	/* Txpower propagation path: TMAC -> TXV -> BBP */
 	len += scnprintf(buf + len, sz - len,
 			 "\nPhy%d Tx power table (channel %d)\n",