[1/3] mt76: mt7663u: fix memory leak in set key
diff mbox series

Message ID 5e8786d9cf0ccd09dd9c13c24c48ce441afbf0ff.1593491298.git.sean.wang@mediatek.com
State New
Headers show
Series
  • [1/3] mt76: mt7663u: fix memory leak in set key
Related show

Commit Message

Sean Wang June 30, 2020, 4:37 a.m. UTC
From: Sean Wang <sean.wang@mediatek.com>

Fix memory leak in set key.

Fixes: eb99cc95c3b6 ("mt76: mt7615: introduce mt7663u support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7615/usb.c   | 22 +++++++++++++------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Lorenzo Bianconi June 30, 2020, 7:07 a.m. UTC | #1
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Fix memory leak in set key.
> 

Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>

> Fixes: eb99cc95c3b6 ("mt76: mt7615: introduce mt7663u support")
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  .../net/wireless/mediatek/mt76/mt7615/usb.c   | 22 +++++++++++++------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> index 0ba28d37c414..96a081be108e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> @@ -165,12 +165,16 @@ __mt7663u_mac_set_key(struct mt7615_dev *dev,
>  
>  	lockdep_assert_held(&dev->mt76.mutex);
>  
> -	if (!sta)
> -		return -EINVAL;
> +	if (!sta) {
> +		err = -EINVAL;
> +		goto out;
> +	}
>  
>  	cipher = mt7615_mac_get_cipher(key->cipher);
> -	if (cipher == MT_CIPHER_NONE)
> -		return -EOPNOTSUPP;
> +	if (cipher == MT_CIPHER_NONE) {
> +		err = -EOPNOTSUPP;
> +		goto out;
> +	}
>  
>  	wcid = &wd->sta->wcid;
>  
> @@ -178,19 +182,23 @@ __mt7663u_mac_set_key(struct mt7615_dev *dev,
>  	err = mt7615_mac_wtbl_update_key(dev, wcid, key->key, key->keylen,
>  					 cipher, key->cmd);
>  	if (err < 0)
> -		return err;
> +		goto out;
>  
>  	err = mt7615_mac_wtbl_update_pk(dev, wcid, cipher, key->keyidx,
>  					key->cmd);
>  	if (err < 0)
> -		return err;
> +		goto out;
>  
>  	if (key->cmd == SET_KEY)
>  		wcid->cipher |= BIT(cipher);
>  	else
>  		wcid->cipher &= ~BIT(cipher);
>  
> -	return 0;
> +out:
> +	kfree(key->key);
> +	kfree(wd);
> +
> +	return err;
>  }
>  
>  void mt7663u_wtbl_work(struct work_struct *work)
> -- 
> 2.25.1
Lorenzo Bianconi June 30, 2020, 7:24 a.m. UTC | #2
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Fix memory leak in set key.
> 
> Fixes: eb99cc95c3b6 ("mt76: mt7615: introduce mt7663u support")
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  .../net/wireless/mediatek/mt76/mt7615/usb.c   | 22 +++++++++++++------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> index 0ba28d37c414..96a081be108e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
> @@ -165,12 +165,16 @@ __mt7663u_mac_set_key(struct mt7615_dev *dev,
>  
>  	lockdep_assert_held(&dev->mt76.mutex);
>  
> -	if (!sta)
> -		return -EINVAL;
> +	if (!sta) {
> +		err = -EINVAL;
> +		goto out;
> +	}
>  
>  	cipher = mt7615_mac_get_cipher(key->cipher);
> -	if (cipher == MT_CIPHER_NONE)
> -		return -EOPNOTSUPP;
> +	if (cipher == MT_CIPHER_NONE) {
> +		err = -EOPNOTSUPP;
> +		goto out;
> +	}
>  
>  	wcid = &wd->sta->wcid;
>  
> @@ -178,19 +182,23 @@ __mt7663u_mac_set_key(struct mt7615_dev *dev,
>  	err = mt7615_mac_wtbl_update_key(dev, wcid, key->key, key->keylen,
>  					 cipher, key->cmd);
>  	if (err < 0)
> -		return err;
> +		goto out;
>  
>  	err = mt7615_mac_wtbl_update_pk(dev, wcid, cipher, key->keyidx,
>  					key->cmd);
>  	if (err < 0)
> -		return err;
> +		goto out;
>  
>  	if (key->cmd == SET_KEY)
>  		wcid->cipher |= BIT(cipher);
>  	else
>  		wcid->cipher &= ~BIT(cipher);
>  
> -	return 0;
> +out:
> +	kfree(key->key);
> +	kfree(wd);

Actually we do not need to free wd since it is done in mt7663u_wtbl_work()

> +
> +	return err;
>  }
>  
>  void mt7663u_wtbl_work(struct work_struct *work)
> -- 
> 2.25.1
Sean Wang June 30, 2020, 9:41 p.m. UTC | #3
From: Sean Wang <sean.wang@mediatek.com>

Thanks, I'll have the next version to remove the unneeded kfree.

>
>> +
>> +	return err;
>>  }
>>
>>  void mt7663u_wtbl_work(struct work_struct *work)

Patch
diff mbox series

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
index 0ba28d37c414..96a081be108e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
@@ -165,12 +165,16 @@  __mt7663u_mac_set_key(struct mt7615_dev *dev,
 
 	lockdep_assert_held(&dev->mt76.mutex);
 
-	if (!sta)
-		return -EINVAL;
+	if (!sta) {
+		err = -EINVAL;
+		goto out;
+	}
 
 	cipher = mt7615_mac_get_cipher(key->cipher);
-	if (cipher == MT_CIPHER_NONE)
-		return -EOPNOTSUPP;
+	if (cipher == MT_CIPHER_NONE) {
+		err = -EOPNOTSUPP;
+		goto out;
+	}
 
 	wcid = &wd->sta->wcid;
 
@@ -178,19 +182,23 @@  __mt7663u_mac_set_key(struct mt7615_dev *dev,
 	err = mt7615_mac_wtbl_update_key(dev, wcid, key->key, key->keylen,
 					 cipher, key->cmd);
 	if (err < 0)
-		return err;
+		goto out;
 
 	err = mt7615_mac_wtbl_update_pk(dev, wcid, cipher, key->keyidx,
 					key->cmd);
 	if (err < 0)
-		return err;
+		goto out;
 
 	if (key->cmd == SET_KEY)
 		wcid->cipher |= BIT(cipher);
 	else
 		wcid->cipher &= ~BIT(cipher);
 
-	return 0;
+out:
+	kfree(key->key);
+	kfree(wd);
+
+	return err;
 }
 
 void mt7663u_wtbl_work(struct work_struct *work)