* [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init()
@ 2021-08-13 20:14 Nathan Chancellor
2021-08-13 21:55 ` Fabio M. De Francesco
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Nathan Chancellor @ 2021-08-13 20:14 UTC (permalink / raw)
To: Greg Kroah-Hartman, Phillip Potter, Larry Finger
Cc: linux-staging, linux-kernel, Nathan Chancellor, Fabio M . De Francesco
ret is unnecessary as both error paths set the same error code so just
return that directly.
Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
drivers/staging/r8188eu/os_dep/usb_intf.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
index 667f41125a87..3e5f4b5eb0fc 100644
--- a/drivers/staging/r8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
@@ -705,22 +705,18 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
{
struct adapter *if1 = NULL;
struct dvobj_priv *dvobj;
- int ret;
/* step 0. */
process_spec_devid(pdid);
/* Initialize dvobj_priv */
dvobj = usb_dvobj_init(pusb_intf);
- if (!dvobj) {
- ret = -ENODEV;
+ if (!dvobj)
goto err;
- }
if1 = rtw_usb_if1_init(dvobj, pusb_intf);
if (!if1) {
DBG_88E("rtw_init_primarystruct adapter Failed!\n");
- ret = -ENODEV;
goto free_dvobj;
}
@@ -734,7 +730,7 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
free_dvobj:
usb_dvobj_deinit(pusb_intf);
err:
- return ret;
+ return -ENODEV;
}
/*
base-commit: 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
--
2.33.0.rc2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init()
2021-08-13 20:14 [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init() Nathan Chancellor
@ 2021-08-13 21:55 ` Fabio M. De Francesco
2021-08-14 17:16 ` Phillip Potter
2021-08-16 9:05 ` Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-08-13 21:55 UTC (permalink / raw)
To: Greg Kroah-Hartman, Phillip Potter, Larry Finger, Nathan Chancellor
Cc: linux-staging, linux-kernel
On Friday, August 13, 2021 10:14:18 PM CEST Nathan Chancellor wrote:
> ret is unnecessary as both error paths set the same error code so just
> return that directly.
>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Much nicer!
Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Thanks,
Fabio
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init()
2021-08-13 20:14 [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init() Nathan Chancellor
2021-08-13 21:55 ` Fabio M. De Francesco
@ 2021-08-14 17:16 ` Phillip Potter
2021-08-16 9:05 ` Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: Phillip Potter @ 2021-08-14 17:16 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Greg Kroah-Hartman, Larry Finger, linux-staging,
Linux Kernel Mailing List, Fabio M . De Francesco
On Fri, 13 Aug 2021 at 21:14, Nathan Chancellor <nathan@kernel.org> wrote:
>
> ret is unnecessary as both error paths set the same error code so just
> return that directly.
>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> drivers/staging/r8188eu/os_dep/usb_intf.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
> index 667f41125a87..3e5f4b5eb0fc 100644
> --- a/drivers/staging/r8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
> @@ -705,22 +705,18 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
> {
> struct adapter *if1 = NULL;
> struct dvobj_priv *dvobj;
> - int ret;
>
> /* step 0. */
> process_spec_devid(pdid);
>
> /* Initialize dvobj_priv */
> dvobj = usb_dvobj_init(pusb_intf);
> - if (!dvobj) {
> - ret = -ENODEV;
> + if (!dvobj)
> goto err;
> - }
>
> if1 = rtw_usb_if1_init(dvobj, pusb_intf);
> if (!if1) {
> DBG_88E("rtw_init_primarystruct adapter Failed!\n");
> - ret = -ENODEV;
> goto free_dvobj;
> }
>
> @@ -734,7 +730,7 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
> free_dvobj:
> usb_dvobj_deinit(pusb_intf);
> err:
> - return ret;
> + return -ENODEV;
> }
>
> /*
>
> base-commit: 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
> --
> 2.33.0.rc2
>
Dear Nathan,
Thanks for this.
Acked-by: Phillip Potter <phil@philpotter.co.uk>
Regards,
Phil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init()
2021-08-13 20:14 [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init() Nathan Chancellor
2021-08-13 21:55 ` Fabio M. De Francesco
2021-08-14 17:16 ` Phillip Potter
@ 2021-08-16 9:05 ` Dan Carpenter
2021-08-16 10:15 ` Fabio M. De Francesco
2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-08-16 9:05 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Greg Kroah-Hartman, Phillip Potter, Larry Finger, linux-staging,
linux-kernel, Fabio M . De Francesco
To be honest, I prefered the original.
foo = alloc();
if (!foo) {
ret = -EWHATEVER;
goto free_last_thing;
}
I like this style of error handling because all the information is
there. You don't need to scroll down.
I don't really care about this specific patch at all. It's a small
thing. But we had someone come through who was sort of obsessed with
removing these sorts of variables. Just because you can remove a
variable doesn't necessarily make the code more readable.
If you're doing the work and maintaining the driver you get to choose
your own style to some extent. But I don't want to encourage people to
start sending these sort of patches more generally.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init()
2021-08-16 9:05 ` Dan Carpenter
@ 2021-08-16 10:15 ` Fabio M. De Francesco
0 siblings, 0 replies; 5+ messages in thread
From: Fabio M. De Francesco @ 2021-08-16 10:15 UTC (permalink / raw)
To: Nathan Chancellor, Dan Carpenter
Cc: Greg Kroah-Hartman, Phillip Potter, Larry Finger, linux-staging,
linux-kernel
On Monday, August 16, 2021 11:05:00 AM CEST Dan Carpenter wrote:
> To be honest, I prefered the original.
>
> foo = alloc();
> if (!foo) {
> ret = -EWHATEVER;
> goto free_last_thing;
> }
>
> I like this style of error handling because all the information is
> there. You don't need to scroll down.
>
Thinking deeper about this style of error handling, I find that Dan is quite
right in preferring readability over removal of (technically unnecessary)
temporary variables. Perhaps the trade-off between brevity and readability
should (in general) favor the latter.
Furthermore, those temporary variables make the code easily adaptable/
extensible in cases where, in future revisions of the code, there will be more
different errors to handle.
However, it's mainly a matter of style, so...
>
> I don't really care about this specific patch at all. It's a small
> thing. But we had someone come through who was sort of obsessed with
> removing these sorts of variables. Just because you can remove a
> variable doesn't necessarily make the code more readable.
>
> If you're doing the work and maintaining the driver you get to choose
> your own style to some extent.
>
I agree: choose your own style (to some extent).
Thanks,
Fabio
>
> But I don't want to encourage people to
> start sending these sort of patches more generally.
>
> regards,
> dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-16 10:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 20:14 [PATCH] staging: r8188eu: Remove unnecessary ret variable in rtw_drv_init() Nathan Chancellor
2021-08-13 21:55 ` Fabio M. De Francesco
2021-08-14 17:16 ` Phillip Potter
2021-08-16 9:05 ` Dan Carpenter
2021-08-16 10:15 ` Fabio M. De Francesco
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).