linux-x25.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Schiller <ms@dev.tdt.de>
To: Yajun Deng <yajun.deng@linux.dev>
Cc: davem@davemloft.net, kuba@kernel.org, linux-x25@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: x25: Optimize the code in {compat_}x25_subscr_ioctl()
Date: Thu, 01 Jul 2021 07:51:10 +0200	[thread overview]
Message-ID: <c9af2f27b8459af35c91ec3347a96d6d@dev.tdt.de> (raw)
In-Reply-To: <20210630091521.15568-1-yajun.deng@linux.dev>

On 2021-06-30 11:15, Yajun Deng wrote:
> Combine the redundant return values, make it more concise.
> 
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
> ---
>  net/x25/af_x25.c   | 19 ++++++++-----------
>  net/x25/x25_link.c | 21 ++++++++++-----------
>  2 files changed, 18 insertions(+), 22 deletions(-)
> 
> diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
> index 3583354a7d7f..53c40fc7c1fd 100644
> --- a/net/x25/af_x25.c
> +++ b/net/x25/af_x25.c
> @@ -1625,21 +1625,19 @@ static int compat_x25_subscr_ioctl(unsigned int 
> cmd,
>  	struct net_device *dev;
>  	int rc = -EINVAL;
> 
> -	rc = -EFAULT;
> -	if (copy_from_user(&x25_subscr, x25_subscr32, sizeof(*x25_subscr32)))
> +	if (copy_from_user(&x25_subscr, x25_subscr32, sizeof(*x25_subscr32))) 
> {
> +		rc = -EFAULT;
>  		goto out;
> +	}
> 
> -	rc = -EINVAL;
>  	dev = x25_dev_get(x25_subscr.device);
> -	if (dev == NULL)
> +	if (!dev)
>  		goto out;
> 
>  	nb = x25_get_neigh(dev);
> -	if (nb == NULL)
> +	if (!nb)
>  		goto out_dev_put;
> 
> -	dev_put(dev);
> -
>  	if (cmd == SIOCX25GSUBSCRIP) {
>  		read_lock_bh(&x25_neigh_list_lock);
>  		x25_subscr.extended = nb->extended;
> @@ -1648,7 +1646,6 @@ static int compat_x25_subscr_ioctl(unsigned int 
> cmd,
>  		rc = copy_to_user(x25_subscr32, &x25_subscr,
>  				sizeof(*x25_subscr32)) ? -EFAULT : 0;
>  	} else {
> -		rc = -EINVAL;
>  		if (x25_subscr.extended == 0 || x25_subscr.extended == 1) {
>  			rc = 0;
>  			write_lock_bh(&x25_neigh_list_lock);
> @@ -1658,11 +1655,11 @@ static int compat_x25_subscr_ioctl(unsigned int 
> cmd,
>  		}
>  	}
>  	x25_neigh_put(nb);
> -out:
> -	return rc;
> +
>  out_dev_put:
>  	dev_put(dev);
> -	goto out;
> +out:
> +	return rc;
>  }
> 
>  static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
> diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
> index 5460b9146dd8..01a13ec88ce8 100644
> --- a/net/x25/x25_link.c
> +++ b/net/x25/x25_link.c
> @@ -360,19 +360,19 @@ int x25_subscr_ioctl(unsigned int cmd, void 
> __user *arg)
>  	if (cmd != SIOCX25GSUBSCRIP && cmd != SIOCX25SSUBSCRIP)
>  		goto out;
> 
> -	rc = -EFAULT;
> -	if (copy_from_user(&x25_subscr, arg, sizeof(x25_subscr)))
> +	if (copy_from_user(&x25_subscr, arg, sizeof(x25_subscr))) {
> +		rc = -EFAULT;
>  		goto out;
> +	}
> 
> -	rc = -EINVAL;
> -	if ((dev = x25_dev_get(x25_subscr.device)) == NULL)
> +	dev = x25_dev_get(x25_subscr.device);
> +	if (!dev)
>  		goto out;
> 
> -	if ((nb = x25_get_neigh(dev)) == NULL)
> +	nb = x25_get_neigh(dev);
> +	if (!nb)
>  		goto out_dev_put;
> 
> -	dev_put(dev);
> -
>  	if (cmd == SIOCX25GSUBSCRIP) {
>  		read_lock_bh(&x25_neigh_list_lock);
>  		x25_subscr.extended	     = nb->extended;
> @@ -381,7 +381,6 @@ int x25_subscr_ioctl(unsigned int cmd, void __user 
> *arg)
>  		rc = copy_to_user(arg, &x25_subscr,
>  				  sizeof(x25_subscr)) ? -EFAULT : 0;
>  	} else {
> -		rc = -EINVAL;
>  		if (!(x25_subscr.extended && x25_subscr.extended != 1)) {
>  			rc = 0;
>  			write_lock_bh(&x25_neigh_list_lock);
> @@ -391,11 +390,11 @@ int x25_subscr_ioctl(unsigned int cmd, void 
> __user *arg)
>  		}
>  	}
>  	x25_neigh_put(nb);
> -out:
> -	return rc;
> +
>  out_dev_put:
>  	dev_put(dev);
> -	goto out;
> +out:
> +	return rc;
>  }

Looks good to me.

Acked-by: Martin Schiller <ms@dev.tdt.de>

      reply	other threads:[~2021-07-01  5:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  9:15 [PATCH] net: x25: Optimize the code in {compat_}x25_subscr_ioctl() Yajun Deng
2021-07-01  5:51 ` Martin Schiller [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=c9af2f27b8459af35c91ec3347a96d6d@dev.tdt.de \
    --to=ms@dev.tdt.de \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-x25@vger.kernel.org \
    --cc=yajun.deng@linux.dev \
    /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).