staging: r8188eu: remove unnecessary NULL check
PATCH 1/1 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.
--- drivers/staging/r8188eu/os_dep/usb_intf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/r8188eu/os_dep/usb_intf.c +1 -2
@@ -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)
Signature · 1 line
2.25.1
Quoted 5 lines · Vihas Mak
remove unnecessary NULL check surrounding
rtw_free_netdev(), as the check is already performed insidertw_free_netdev()indrivers/staging/r8188eu/os_dep/osdep_service.c.Signed-off-by Vihas Mak <[email protected]>
BTW, same can be done in rtw_usb_if1_init().
With regards,
Pavel Skripkin
Quoted 1 line
Quoted 1 line
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
Quoted 16 lines · Pavel Skripkin
Quoted 5 lines · Vihas Mak
remove unnecessary NULL check surrounding
rtw_free_netdev(), as the check is already performed insidertw_free_netdev()indrivers/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
Quoted 14 lines · Vihas Mak
remove unnecessary NULL check surrounding
rtw_free_netdev(), as the check is already performed insidertw_free_netdev()indrivers/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(-)drivers/staging/r8188eu/os_dep/usb_intf.c +0
-0
drivers/staging/r8188eu/os_dep/usb_intf.c static void rtw_usb_if1_deinit(struct adapter *if1) · line 470
Quoted 7 lines
drivers/staging/r8188eu/os_dep/usb_intf.c +1
-2@@ -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
Greg KH
maintainerQuoted 14 lines · Vihas Mak
remove unnecessary NULL check surrounding
rtw_free_netdev(), as the check is already performed insidertw_free_netdev()indrivers/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(-)drivers/staging/r8188eu/os_dep/usb_intf.c +0
-0
drivers/staging/r8188eu/os_dep/usb_intf.c static void rtw_usb_if1_deinit(struct adapter *if1) · line 469
Quoted 6 lines
drivers/staging/r8188eu/os_dep/usb_intf.c +1
-2@@ -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
Quoted 1 line
Quoted 1 line
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.
Quoted 30 lines · Greg KH
Quoted 14 lines · Vihas Mak
remove unnecessary NULL check surrounding
rtw_free_netdev(), as the check is already performed insidertw_free_netdev()indrivers/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(-)drivers/staging/r8188eu/os_dep/usb_intf.c +0
-0drivers/staging/r8188eu/os_dep/usb_intf.c static void rtw_usb_if1_deinit(struct adapter *if1) · line 469
Quoted 6 lines
drivers/staging/r8188eu/os_dep/usb_intf.c +1
-2@@ -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
Signature · 2 lines
Thanks, Vihas
Quoted 8 lines · Vihas Mak
Quoted 1 line
Quoted 1 line
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 callingrtw_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