* [PATCH v2] staging: r8188eu: handle rtw_init_netdev_name() failure appropriately
@ 2022-01-23 18:17 Vihas Mak
2022-01-24 6:49 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Vihas Mak @ 2022-01-23 18:17 UTC (permalink / raw)
To: Larry Finger, Phillip Potter, Greg Kroah-Hartman, Michael Straube,
Martin Kaiser
Cc: Dan Carpenter, linux-staging, linux-kernel, Vihas Mak
rtw_init_netdev_name() calls dev_alloc_name() which allocates the name
for the device as per the given name format.
The name format is specified by the module parameter "ifname".
It returns a negative err code if the format is invalid. Handle this
error appropriately.
Cancel the timers ininitliazed by rtw_init_drv_sw() before calling
rtw_free_drv_sw() and then proceed to free the adapter.
Also, if register_netdev() fails then goto free_drv_sw instead of
goto handle_dualmac.
Signed-off-by: Vihas Mak <makvihas@gmail.com>
---
v1->v2:
free the adapter and netdev instead of warning the user about
allocation failure.
drivers/staging/r8188eu/os_dep/usb_intf.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
index 91792dfd3..85b5d0bd7 100644
--- a/drivers/staging/r8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
@@ -399,7 +399,11 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
DBG_88E("can't get autopm:\n");
/* alloc dev name after read efuse. */
- rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
+ if (rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname) < 0) {
+ DBG_88E("rtw_init_netdev_name failed, ifname:%s\n",
+ padapter->registrypriv.ifname);
+ goto free_drv_sw;
+ }
rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr,
padapter->eeprompriv.mac_addr);
@@ -409,7 +413,7 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
/* step 6. Tell the network stack we exist */
if (register_netdev(pnetdev) != 0)
- goto handle_dualmac;
+ goto free_drv_sw;
DBG_88E("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
, padapter->bDriverStopped
@@ -420,6 +424,11 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
status = _SUCCESS;
+free_drv_sw:
+ if (status != _SUCCESS) {
+ rtw_cancel_all_timer(padapter);
+ rtw_free_drv_sw(padapter);
+ }
handle_dualmac:
if (status != _SUCCESS)
rtw_handle_dualmac(padapter, 0);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: r8188eu: handle rtw_init_netdev_name() failure appropriately
2022-01-23 18:17 [PATCH v2] staging: r8188eu: handle rtw_init_netdev_name() failure appropriately Vihas Mak
@ 2022-01-24 6:49 ` Dan Carpenter
2022-01-24 9:16 ` Vihas Mak
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-01-24 6:49 UTC (permalink / raw)
To: Vihas Mak
Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman, Michael Straube,
Martin Kaiser, linux-staging, linux-kernel
On Sun, Jan 23, 2022 at 11:47:35PM +0530, Vihas Mak wrote:
> rtw_init_netdev_name() calls dev_alloc_name() which allocates the name
> for the device as per the given name format.
> The name format is specified by the module parameter "ifname".
> It returns a negative err code if the format is invalid. Handle this
> error appropriately.
> Cancel the timers ininitliazed by rtw_init_drv_sw() before calling
> rtw_free_drv_sw() and then proceed to free the adapter.
>
> Also, if register_netdev() fails then goto free_drv_sw instead of
> goto handle_dualmac.
>
> Signed-off-by: Vihas Mak <makvihas@gmail.com>
> ---
> v1->v2:
> free the adapter and netdev instead of warning the user about
> allocation failure.
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Of course, all this code is staging code and terrible. This function
is needlessly difficult to read/review.
TODO: re-write probe error handling
Step 1: Keep the success path and error path separate.
- status = _SUCCESS;
+ return padapter;
Step 2: Eliminate do-nothing-gotos. s/goto exit/return NULL/
Step 3: Delete the vfree(pnpi->priv); from rtw_free_netdev() and call
vfree(pnpi->priv); from probe and rtw_usb_if1_deinit() instead.
Avoid a layering violation.
Step 4: Every allocation function needs a matching free function. Move
the rtw_cancel_all_timer() into the rtw_free_drv_sw() function.
Open coding it is a layering violation.
Step 5: Get rid of the rtw_handle_dualmac() function. It has a bad
name and a global variable. What is the point of this function?
But that stuff is for later patches.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: r8188eu: handle rtw_init_netdev_name() failure appropriately
2022-01-24 6:49 ` Dan Carpenter
@ 2022-01-24 9:16 ` Vihas Mak
0 siblings, 0 replies; 3+ messages in thread
From: Vihas Mak @ 2022-01-24 9:16 UTC (permalink / raw)
To: Dan Carpenter
Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman, Michael Straube,
Martin Kaiser, linux-staging, linux-kernel
Thanks for reviewing the patch Dan.
>> TODO: re-write probe error handling
Will submit a series of patches in upcoming days, based on the steps
you provided.
On Mon, Jan 24, 2022 at 12:19 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Sun, Jan 23, 2022 at 11:47:35PM +0530, Vihas Mak wrote:
> > rtw_init_netdev_name() calls dev_alloc_name() which allocates the name
> > for the device as per the given name format.
> > The name format is specified by the module parameter "ifname".
> > It returns a negative err code if the format is invalid. Handle this
> > error appropriately.
> > Cancel the timers ininitliazed by rtw_init_drv_sw() before calling
> > rtw_free_drv_sw() and then proceed to free the adapter.
> >
> > Also, if register_netdev() fails then goto free_drv_sw instead of
> > goto handle_dualmac.
> >
> > Signed-off-by: Vihas Mak <makvihas@gmail.com>
> > ---
> > v1->v2:
> > free the adapter and netdev instead of warning the user about
> > allocation failure.
>
> Thanks!
>
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> Of course, all this code is staging code and terrible. This function
> is needlessly difficult to read/review.
>
> TODO: re-write probe error handling
>
> Step 1: Keep the success path and error path separate.
>
> - status = _SUCCESS;
> + return padapter;
>
> Step 2: Eliminate do-nothing-gotos. s/goto exit/return NULL/
>
> Step 3: Delete the vfree(pnpi->priv); from rtw_free_netdev() and call
> vfree(pnpi->priv); from probe and rtw_usb_if1_deinit() instead.
> Avoid a layering violation.
>
> Step 4: Every allocation function needs a matching free function. Move
> the rtw_cancel_all_timer() into the rtw_free_drv_sw() function.
> Open coding it is a layering violation.
>
> Step 5: Get rid of the rtw_handle_dualmac() function. It has a bad
> name and a global variable. What is the point of this function?
>
> But that stuff is for later patches.
>
> regards,
> dan carpenter
>
--
Thanks,
Vihas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-24 9:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-23 18:17 [PATCH v2] staging: r8188eu: handle rtw_init_netdev_name() failure appropriately Vihas Mak
2022-01-24 6:49 ` Dan Carpenter
2022-01-24 9:16 ` Vihas Mak
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).