linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: samirweng1979 <samirweng1979@163.com>
Cc: gustavoars@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	wengjianfeng <wengjianfeng@yulong.com>
Subject: Re: [PATCH] nfc: pn533: remove redundant assignment
Date: Fri, 9 Apr 2021 16:46:41 -0700	[thread overview]
Message-ID: <20210409164641.3334d216@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <20210409115010.33436-1-samirweng1979@163.com>

On Fri,  9 Apr 2021 19:50:09 +0800 samirweng1979 wrote:
> From: wengjianfeng <wengjianfeng@yulong.com>
> 
> In many places,first assign a value to a variable and then return
> the variable. which is redundant, we should directly return the value.
> in pn533_rf_field funciton,return statement in the if statement is
> redundant, we just delete it.
> 
> Signed-off-by: wengjianfeng <wengjianfeng@yulong.com>

Thank you for the changes, please see comments below.

> diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c
> index f1469ac..61ab4c0 100644
> --- a/drivers/nfc/pn533/pn533.c
> +++ b/drivers/nfc/pn533/pn533.c
> @@ -489,12 +489,8 @@ static int pn533_send_data_async(struct pn533 *dev, u8 cmd_code,
>  				 pn533_send_async_complete_t complete_cb,
>  				 void *complete_cb_context)
>  {
> -	int rc;
> -
> -	rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
> +	return __pn533_send_async(dev, cmd_code, req, complete_cb,
>  				complete_cb_context);

Please realign the continuation line so it starts after the opening
bracket.

> -
> -	return rc;
>  }
>  
>  static int pn533_send_cmd_async(struct pn533 *dev, u8 cmd_code,
> @@ -502,12 +498,8 @@ static int pn533_send_cmd_async(struct pn533 *dev, u8 cmd_code,
>  				pn533_send_async_complete_t complete_cb,
>  				void *complete_cb_context)
>  {
> -	int rc;
> -
> -	rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
> +	return __pn533_send_async(dev, cmd_code, req, complete_cb,
>  				complete_cb_context);

Same here.

> -	return rc;
>  }
>  
>  /*
> @@ -2614,7 +2606,6 @@ static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf)
>  				     (u8 *)&rf_field, 1);
>  	if (rc) {
>  		nfc_err(dev->dev, "Error on setting RF field\n");
> -		return rc;
>  	}
>  
>  	return rc;

In case some code is added between the check and the return statement
it'd be better to fix this by replacing the second return rc with
return 0:

	if (rc) {
		nfc_err(...);
		return rc;
	}

	return 0;

> diff --git a/drivers/nfc/pn533/uart.c b/drivers/nfc/pn533/uart.c
> index a0665d8..6465348 100644
> --- a/drivers/nfc/pn533/uart.c
> +++ b/drivers/nfc/pn533/uart.c
> @@ -239,9 +239,8 @@ static int pn532_uart_probe(struct serdev_device *serdev)
>  {
>  	struct pn532_uart_phy *pn532;
>  	struct pn533 *priv;
> -	int err;
> +	int err = -ENOMEM;
>  
> -	err = -ENOMEM;
>  	pn532 = kzalloc(sizeof(*pn532), GFP_KERNEL);

IMO having the assignment before the call is more readable, please
leave as is.

>  	if (!pn532)
>  		goto err_exit;

      reply	other threads:[~2021-04-09 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09 11:50 [PATCH] nfc: pn533: remove redundant assignment samirweng1979
2021-04-09 23:46 ` Jakub Kicinski [this message]

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=20210409164641.3334d216@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
    --to=kuba@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=samirweng1979@163.com \
    --cc=wengjianfeng@yulong.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).