linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Vihas Mak <makvihas@gmail.com>
Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk,
	gregkh@linuxfoundation.org, straube.linux@gmail.com,
	martin@kaiser.cx, paskripkin@gmail.com,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: r8188eu: remove unnecessary NULL check
Date: Tue, 23 Nov 2021 11:06:21 +0300	[thread overview]
Message-ID: <20211123080621.GC6514@kadam> (raw)
In-Reply-To: <20211122195350.GA166134@makvihas>

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 <makvihas@gmail.com>
> ---
>  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

  parent reply	other threads:[~2021-11-23  8:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 19:53 [PATCH] staging: r8188eu: remove unnecessary NULL check Vihas Mak
2021-11-22 21:22 ` Pavel Skripkin
2021-11-23 23:49   ` Vihas Mak
2021-11-23  8:06 ` Dan Carpenter [this message]
2021-11-24 10:00 ` Greg KH
2021-11-25  1:32   ` Vihas Mak
2021-11-25  7:09     ` Dan Carpenter
2022-08-24  8:03 [PATCH] staging: r8188eu: remove unnecessary null check cgel.zte
2022-08-25  6:36 ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211123080621.GC6514@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=makvihas@gmail.com \
    --cc=martin@kaiser.cx \
    --cc=paskripkin@gmail.com \
    --cc=phil@philpotter.co.uk \
    --cc=straube.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).