2021-11-22 19:54:00

by Vihas Makwana

[permalink] [raw]
Subject: [PATCH] staging: r8188eu: remove unnecessary NULL check

remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
is already performed inside rtw_free_netdev() in
drivers/staging/r8188eu/os_dep/osdep_service.c.

Signed-off-by: Vihas Mak <[email protected]>
---
drivers/staging/r8188eu/os_dep/usb_intf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
index 5a35d9fe3fc9..392bd7868519 100644
--- a/drivers/staging/r8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
@@ -466,8 +466,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
if1->hw_init_completed);
rtw_handle_dualmac(if1, 0);
rtw_free_drv_sw(if1);
- if (pnetdev)
- rtw_free_netdev(pnetdev);
+ rtw_free_netdev(pnetdev);
}

static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
--
2.25.1



2021-11-22 21:22:25

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

On 11/22/21 22:53, Vihas Mak wrote:
> remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
> is already performed inside rtw_free_netdev() in
> drivers/staging/r8188eu/os_dep/osdep_service.c.
>
> Signed-off-by: Vihas Mak <[email protected]>

Reviewed-by: Pavel Skripkin <[email protected]>

BTW, same can be done in rtw_usb_if1_init().



With regards,
Pavel Skripkin

2021-11-23 08:06:59

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

On Tue, Nov 23, 2021 at 01:23:50AM +0530, Vihas Mak wrote:
> remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
> is already performed inside rtw_free_netdev() in
> drivers/staging/r8188eu/os_dep/osdep_service.c.
>
> Signed-off-by: Vihas Mak <[email protected]>
> ---
> drivers/staging/r8188eu/os_dep/usb_intf.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
> index 5a35d9fe3fc9..392bd7868519 100644
> --- a/drivers/staging/r8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
> @@ -466,8 +466,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
> if1->hw_init_completed);
> rtw_handle_dualmac(if1, 0);
> rtw_free_drv_sw(if1);
> - if (pnetdev)
> - rtw_free_netdev(pnetdev);
> + rtw_free_netdev(pnetdev);
> }

I'm not a huge fan of these sorts of patches. They don't make the code
more readable because they hide the complexity.

Occasionally we will get a forest cobra in our yard and everyone is
screaming and panicking. I'm like, "Calm down. Once you've spotted the
snake, even a deadly snake, then the danger has passed." You can just
stay two or three meters away and you're fine. Call a snake catcher.

What you're doing here is you've got a potential NULL dereference which
is the snake. And this patch is saying, "Snakes are so messy! Let's
hide it in the bushes next to the sidewalk where no one can see it."

Hash tag, folksy wisdom. #snakes

On the other hand, it might be worth checking if "pnetdev" can even be
NULL at this point, and then deleting both of the NULL checks. That
would be a very good clean up.

regards,
dan carpenter

2021-11-23 23:49:30

by Vihas Makwana

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

>> BTW, same can be done in rtw_usb_if1_init().

Yea, I noticed that too. But the NULL check in rtw_usb_if1_init() has
a follow up "else if", so I didn't change it.

Thanks,
Vihas

On Tue, Nov 23, 2021 at 2:52 AM Pavel Skripkin <[email protected]> wrote:
>
> On 11/22/21 22:53, Vihas Mak wrote:
> > remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
> > is already performed inside rtw_free_netdev() in
> > drivers/staging/r8188eu/os_dep/osdep_service.c.
> >
> > Signed-off-by: Vihas Mak <[email protected]>
>
> Reviewed-by: Pavel Skripkin <[email protected]>
>
> BTW, same can be done in rtw_usb_if1_init().
>
>
>
> With regards,
> Pavel Skripkin

2021-11-24 10:00:27

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

On Tue, Nov 23, 2021 at 01:23:50AM +0530, Vihas Mak wrote:
> remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
> is already performed inside rtw_free_netdev() in
> drivers/staging/r8188eu/os_dep/osdep_service.c.
>
> Signed-off-by: Vihas Mak <[email protected]>
> ---
> drivers/staging/r8188eu/os_dep/usb_intf.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
> index 5a35d9fe3fc9..392bd7868519 100644
> --- a/drivers/staging/r8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
> @@ -466,8 +466,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
> if1->hw_init_completed);
> rtw_handle_dualmac(if1, 0);
> rtw_free_drv_sw(if1);
> - if (pnetdev)
> - rtw_free_netdev(pnetdev);
> + rtw_free_netdev(pnetdev);

As Dan said, this isn't usually a good idea to hide this.

And are you sure this ever could be NULL?

thanks,

greg k-h

2021-11-25 02:02:13

by Vihas Makwana

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

>> And are you sure this ever could be NULL?
Yes.

The function rtw_free_netdev() performs a NULL check before actually
freeing the structure, so the "if (pnetdev)" check isn't really
necessary before calling rtw_free_netdev().
That's the reason why I removed that check.


On Wed, Nov 24, 2021 at 3:30 PM Greg KH <[email protected]> wrote:
>
> On Tue, Nov 23, 2021 at 01:23:50AM +0530, Vihas Mak wrote:
> > remove unnecessary NULL check surrounding rtw_free_netdev(), as the check
> > is already performed inside rtw_free_netdev() in
> > drivers/staging/r8188eu/os_dep/osdep_service.c.
> >
> > Signed-off-by: Vihas Mak <[email protected]>
> > ---
> > drivers/staging/r8188eu/os_dep/usb_intf.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c
> > index 5a35d9fe3fc9..392bd7868519 100644
> > --- a/drivers/staging/r8188eu/os_dep/usb_intf.c
> > +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c
> > @@ -466,8 +466,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
> > if1->hw_init_completed);
> > rtw_handle_dualmac(if1, 0);
> > rtw_free_drv_sw(if1);
> > - if (pnetdev)
> > - rtw_free_netdev(pnetdev);
> > + rtw_free_netdev(pnetdev);
>
> As Dan said, this isn't usually a good idea to hide this.
>
> And are you sure this ever could be NULL?
>
> thanks,
>
> greg k-h



--
Thanks,
Vihas

2021-11-25 07:11:57

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check

On Thu, Nov 25, 2021 at 07:02:20AM +0530, Vihas Mak wrote:
> >> And are you sure this ever could be NULL?
> Yes.
>
> The function rtw_free_netdev() performs a NULL check before actually
> freeing the structure, so the "if (pnetdev)" check isn't really
> necessary before calling rtw_free_netdev().
> That's the reason why I removed that check.
>

That's not the question Greg and I asked. Re-read the emails.

regards,
dan carpenter