public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches•com>
To: Ian Morris <ipm@chirality•org.uk>
Cc: netdev@vger•kernel.org
Subject: Re: [PATCH net-next 6/6] ipv6: netfilter: simply if-else statements
Date: Sat, 25 Apr 2015 09:17:44 -0700	[thread overview]
Message-ID: <1429978664.32250.24.camel@perches.com> (raw)
In-Reply-To: <1429954020-11763-7-git-send-email-ipm@chirality.org.uk>

On Sat, 2015-04-25 at 10:27 +0100, Ian Morris wrote:
> Remove "else" branch of "if" statements where a return is always done
> when the condition is true.

trivia:

> diff --git a/net/ipv6/netfilter/ip6t_hbh.c b/net/ipv6/netfilter/ip6t_hbh.c
[]
> @@ -95,70 +95,67 @@ hbh_mt6(const struct sk_buff *skb, struct xt_action_param *par)
>  
>  	ptr += 2;
>  	hdrlen -= 2;
> -	if (!(optinfo->flags & IP6T_OPTS_OPTS)) {
> +	if (!(optinfo->flags & IP6T_OPTS_OPTS))
>  		return ret;
> -	} else {
> -		pr_debug("Strict ");
> -		pr_debug("#%d ", optinfo->optsnr);
> -		for (temp = 0; temp < optinfo->optsnr; temp++) {
> -			/* type field exists ? */
> -			if (hdrlen < 1)
> +
> +	pr_debug("Strict ");
> +	pr_debug("#%d ", optinfo->optsnr);

I think the logging is a bit broken.

> +	for (temp = 0; temp < optinfo->optsnr; temp++) {
> +		/* type field exists ? */
> +		if (hdrlen < 1)
> +			break;
> +		tp = skb_header_pointer(skb, ptr, sizeof(_opttype),
> +					&_opttype);

fits on a single line
		tp = skb_header_pointer(skb, ptr, sizeof(_opttype), &_opttype);

[]

> +			if (spec_len != 0x00FF && spec_len != *lp) {
> +				pr_debug("Lbad %02X %04X\n", *lp,
> +					 spec_len);

My preference is to keep format and arguments on
separate lines when it's necessary to use multiple lines.

				pr_debug("Lbad %02X %04X\n",
					 *lp, spec_len);

> diff --git a/net/ipv6/netfilter/ip6t_rt.c b/net/ipv6/netfilter/ip6t_rt.c
[]
> @@ -119,66 +119,62 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
[]
> +		pr_debug("#%d ", rtinfo->addrnr);
> +		for (temp = 0;
> +		     temp < (unsigned int)((hdrlen - 8) / 16);

I believe the cast isn't necessary

> +		     temp++) {

so this could be

		for (temp = 0; temp < (hdrlen - 8) / 16, temp++) {

> +			ap = skb_header_pointer(skb,
> +						ptr
> +						+ sizeof(struct rt0_hdr)
> +						+ temp * sizeof(_addr),
> +						sizeof(_addr),
> +						&_addr);

That's an unfortunate calculation of ptr + ...
It might be clearer to use a temporary.

  reply	other threads:[~2015-04-25 16:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-25  9:26 [PATCH net-next 0/6] ipv6: netfilter - coding style improvements Ian Morris
2015-04-25  9:26 ` [PATCH net-next 1/6] ipv6: netfilter: Tidy up indenting Ian Morris
2015-04-25  9:26 ` [PATCH net-next 2/6] ipv6: netfilter: whitespace in line layouts Ian Morris
2015-04-25 15:57   ` Joe Perches
2015-04-25  9:26 ` [PATCH net-next 3/6] ipv6: netfilter: remove unnecessary braces Ian Morris
2015-04-25 15:59   ` Joe Perches
2015-04-25 16:54     ` Sergei Shtylyov
2015-04-25 17:01       ` Joe Perches
2015-04-25  9:26 ` [PATCH net-next 4/6] ipv6: netfilter: comparison for equality with NULL Ian Morris
2015-04-25  9:26 ` [PATCH net-next 5/6] ipv6: netfilter: comparison for inequality " Ian Morris
2015-04-25  9:27 ` [PATCH net-next 6/6] ipv6: netfilter: simply if-else statements Ian Morris
2015-04-25 16:17   ` Joe Perches [this message]
2015-04-27  2:43 ` [PATCH net-next 0/6] ipv6: netfilter - coding style improvements Pablo Neira Ayuso

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=1429978664.32250.24.camel@perches.com \
    --to=joe@perches$(echo .)com \
    --cc=ipm@chirality$(echo .)org.uk \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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