Subject: Re: [PATCH net-next 6/6] ipv6: netfilter: simply if-else statements

From: Joe Perches <[email-masked]>
Date: Sat, 25 Apr 2015 09:17:44 -0700

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.