diff mbox series

ipw2200: fix memory leak in ipw_wdev_init()

Message ID 20221208122630.2850534-1-shaozhengchao@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ipw2200: fix memory leak in ipw_wdev_init() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

shaozhengchao Dec. 8, 2022, 12:26 p.m. UTC
In the error path of ipw_wdev_init(), exception value is returned, and
the memory applied for in the function is not released. Also the memory
is not released in ipw_pci_probe(). As a result, memory leakage occurs.
So memory release needs to be added to the error path of ipw_wdev_init().

Fixes: a3caa99e6c68 ("libipw: initiate cfg80211 API conversion (v2)")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 drivers/net/wireless/intel/ipw2x00/ipw2200.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jiri Pirko Dec. 8, 2022, 1 p.m. UTC | #1
Thu, Dec 08, 2022 at 01:26:30PM CET, shaozhengchao@huawei.com wrote:
>In the error path of ipw_wdev_init(), exception value is returned, and
>the memory applied for in the function is not released. Also the memory
>is not released in ipw_pci_probe(). As a result, memory leakage occurs.
>So memory release needs to be added to the error path of ipw_wdev_init().
>
>Fixes: a3caa99e6c68 ("libipw: initiate cfg80211 API conversion (v2)")
>Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>---
> drivers/net/wireless/intel/ipw2x00/ipw2200.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>index 5b483de18c81..cead5c7fc91e 100644
>--- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>+++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>@@ -11397,9 +11397,15 @@ static int ipw_wdev_init(struct net_device *dev)
> 	set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
> 
> 	/* With that information in place, we can now register the wiphy... */
>-	if (wiphy_register(wdev->wiphy))
>+	if (wiphy_register(wdev->wiphy)) {

While you are at it, how about to take the actual return value of
wiphy_register() into account?


> 		rc = -EIO;
>+		goto out;
>+	}
>+
>+	return 0;
> out:
>+	kfree(priv->ieee->a_band.channels);
>+	kfree(priv->ieee->bg_band.channels);
> 	return rc;
> }
> 
>-- 
>2.34.1
>
shaozhengchao Dec. 9, 2022, 1:01 a.m. UTC | #2
On 2022/12/8 21:00, Jiri Pirko wrote:
> Thu, Dec 08, 2022 at 01:26:30PM CET, shaozhengchao@huawei.com wrote:
>> In the error path of ipw_wdev_init(), exception value is returned, and
>> the memory applied for in the function is not released. Also the memory
>> is not released in ipw_pci_probe(). As a result, memory leakage occurs.
>> So memory release needs to be added to the error path of ipw_wdev_init().
>>
>> Fixes: a3caa99e6c68 ("libipw: initiate cfg80211 API conversion (v2)")
>> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>> ---
>> drivers/net/wireless/intel/ipw2x00/ipw2200.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>> index 5b483de18c81..cead5c7fc91e 100644
>> --- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>> +++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
>> @@ -11397,9 +11397,15 @@ static int ipw_wdev_init(struct net_device *dev)
>> 	set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
>>
>> 	/* With that information in place, we can now register the wiphy... */
>> -	if (wiphy_register(wdev->wiphy))
>> +	if (wiphy_register(wdev->wiphy)) {
> 
> While you are at it, how about to take the actual return value of
> wiphy_register() into account?
> 
> 
Hi Jiri:
	Thank you for your suggestion. I will change it in V2.

Zhengchao Shao
>> 		rc = -EIO;
>> +		goto out;
>> +	}
>> +
>> +	return 0;
>> out:
>> +	kfree(priv->ieee->a_band.channels);
>> +	kfree(priv->ieee->bg_band.channels);
>> 	return rc;
>> }
>>
>> -- 
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
index 5b483de18c81..cead5c7fc91e 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
@@ -11397,9 +11397,15 @@  static int ipw_wdev_init(struct net_device *dev)
 	set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
 
 	/* With that information in place, we can now register the wiphy... */
-	if (wiphy_register(wdev->wiphy))
+	if (wiphy_register(wdev->wiphy)) {
 		rc = -EIO;
+		goto out;
+	}
+
+	return 0;
 out:
+	kfree(priv->ieee->a_band.channels);
+	kfree(priv->ieee->bg_band.channels);
 	return rc;
 }