* [PATCH -next v2] staging: rtl8192e: rtllib_module: fix missing free_netdev() on error in alloc_rtllib()
@ 2021-12-01 6:29 Yang Yingliang
2021-12-01 7:04 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2021-12-01 6:29 UTC (permalink / raw)
To: linux-kernel, linux-staging; +Cc: gregkh, paskripkin
Add the missing free_netdev() before return from alloc_rtllib()
in the error handling case.
Return error code from rtllib_softmac_init(), so it can be checked
in alloc_rtllib().
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v2:
return error code from rtllib_softmac_init() and add check return value
of rtllib_softmac_init().
---
drivers/staging/rtl8192e/rtllib.h | 2 +-
drivers/staging/rtl8192e/rtllib_module.c | 5 +++--
drivers/staging/rtl8192e/rtllib_softmac.c | 7 +++++--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index c6f8b772335c..c985e4ebc545 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -1980,7 +1980,7 @@ void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
void rtllib_start_ibss(struct rtllib_device *ieee);
-void rtllib_softmac_init(struct rtllib_device *ieee);
+int rtllib_softmac_init(struct rtllib_device *ieee);
void rtllib_softmac_free(struct rtllib_device *ieee);
void rtllib_disassociate(struct rtllib_device *ieee);
void rtllib_stop_scan(struct rtllib_device *ieee);
diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
index 64d9feee1f39..105c58e749d6 100644
--- a/drivers/staging/rtl8192e/rtllib_module.c
+++ b/drivers/staging/rtl8192e/rtllib_module.c
@@ -121,11 +121,12 @@ struct net_device *alloc_rtllib(int sizeof_priv)
ieee->hwsec_active = 0;
memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
- rtllib_softmac_init(ieee);
+ if (rtllib_softmac_init(ieee))
+ goto failed;
ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
if (!ieee->pHTInfo)
- return NULL;
+ goto failed;
HTUpdateDefaultSetting(ieee);
HTInitializeHTInfo(ieee);
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index aabbea48223d..c4af056ddd82 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -2952,7 +2952,7 @@ void rtllib_start_protocol(struct rtllib_device *ieee)
}
}
-void rtllib_softmac_init(struct rtllib_device *ieee)
+int rtllib_softmac_init(struct rtllib_device *ieee)
{
int i;
@@ -2962,8 +2962,10 @@ void rtllib_softmac_init(struct rtllib_device *ieee)
for (i = 0; i < 5; i++)
ieee->seq_ctrl[i] = 0;
ieee->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
- if (!ieee->dot11d_info)
+ if (!ieee->dot11d_info) {
netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n");
+ return -ENOMEM;
+ }
ieee->LinkDetectInfo.SlotIndex = 0;
ieee->LinkDetectInfo.SlotNum = 2;
ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
@@ -3029,6 +3031,7 @@ void rtllib_softmac_init(struct rtllib_device *ieee)
tasklet_setup(&ieee->ps_task, rtllib_sta_ps);
+ return 0;
}
void rtllib_softmac_free(struct rtllib_device *ieee)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next v2] staging: rtl8192e: rtllib_module: fix missing free_netdev() on error in alloc_rtllib()
2021-12-01 6:29 [PATCH -next v2] staging: rtl8192e: rtllib_module: fix missing free_netdev() on error in alloc_rtllib() Yang Yingliang
@ 2021-12-01 7:04 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2021-12-01 7:04 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-kernel, linux-staging, gregkh, paskripkin
I just sent an reply to the v1 patch with more explanations.
On Wed, Dec 01, 2021 at 02:29:08PM +0800, Yang Yingliang wrote:
> diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
> index 64d9feee1f39..105c58e749d6 100644
> --- a/drivers/staging/rtl8192e/rtllib_module.c
> +++ b/drivers/staging/rtl8192e/rtllib_module.c
> @@ -121,11 +121,12 @@ struct net_device *alloc_rtllib(int sizeof_priv)
> ieee->hwsec_active = 0;
>
> memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
> - rtllib_softmac_init(ieee);
> + if (rtllib_softmac_init(ieee))
> + goto failed;
Please write this like so:
err = rtllib_softmac_init(ieee);
if (err)
goto failed;
Otherwise it suggests that rtllib_softmac_init() returns boolean or
something. I suggest changing rtllib_softmac_init() in a separate
patch 2/2.
> @@ -2962,8 +2962,10 @@ void rtllib_softmac_init(struct rtllib_device *ieee)
> for (i = 0; i < 5; i++)
> ieee->seq_ctrl[i] = 0;
> ieee->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
> - if (!ieee->dot11d_info)
> + if (!ieee->dot11d_info) {
> netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n");
This error message should be deleted. The kzalloc() function already
has a more useful message.
> + return -ENOMEM;
> + }
> ieee->LinkDetectInfo.SlotIndex = 0;
> ieee->LinkDetectInfo.SlotNum = 2;
> ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-01 7:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-01 6:29 [PATCH -next v2] staging: rtl8192e: rtllib_module: fix missing free_netdev() on error in alloc_rtllib() Yang Yingliang
2021-12-01 7:04 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).