From: Joe Perches <joe@perches.com>
To: yuan linyu <cugyly@163.com>, netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
Subject: Re: [PATCH net-next v5] net: ipv6: fix code style error and warning of ndisc.c
Date: Sun, 21 May 2017 09:05:08 -0700 [thread overview]
Message-ID: <1495382708.2093.10.camel@perches.com> (raw)
In-Reply-To: <1495328154-18653-1-git-send-email-cugyly@163.com>
On Sun, 2017-05-21 at 08:55 +0800, yuan linyu wrote:
> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>
> diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
[]
> @@ -512,7 +519,8 @@ void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr,
> in6_ifa_put(ifp);
> } else {
> if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
> - inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
> + inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->
> + srcprefs,
This is not a good change as it puts a single dereference
on multiple lines.
> @@ -896,20 +910,19 @@ static void ndisc_recv_ns(struct sk_buff *skb)
> else
> NEIGH_CACHE_STAT_INC(&nd_tbl, rcv_probes_ucast);
>
> - /*
> - * update / create cache entry
> + /* update / create cache entry
> * for the source address
Some of these comments could be single line
> @@ -1003,30 +1016,31 @@ static void ndisc_recv_na(struct sk_buff *skb)
[]
> ndisc_update(dev, neigh, lladdr,
> - msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE,
> - NEIGH_UPDATE_F_WEAK_OVERRIDE|
> - (msg->icmph.icmp6_override ? NEIGH_UPDATE_F_OVERRIDE : 0)|
> - NEIGH_UPDATE_F_OVERRIDE_ISROUTER|
> - (msg->icmph.icmp6_router ? NEIGH_UPDATE_F_ISROUTER : 0),
> + msg->icmph.icmp6_solicited ?
> + NUD_REACHABLE : NUD_STALE,
> + NEIGH_UPDATE_F_WEAK_OVERRIDE |
> + (msg->icmph.icmp6_override ?
> + NEIGH_UPDATE_F_OVERRIDE : 0) |
> + NEIGH_UPDATE_F_OVERRIDE_ISROUTER |
> + (msg->icmph.icmp6_router ?
> + NEIGH_UPDATE_F_ISROUTER : 0),
> NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts);
This is much more difficult to read now and could
be slightly improved by a temporary for msg->icmph,
removing unnecessary parentheses or using multiple
line tests for the flags argument of ndisc_update
instead of the slightly difficult to read uses of
multiple ternaries with bitwise ORs.
Something like:
struct icmp6hdr *icmph = &msg->icmph;
u32 flags;
[...]
flags = NEIGH_UPDATE_F_WEAK_OVERRIDE | NEIGH_UPDATE_F_OVERRIDE_ISROUTER;
if (icmph->icmp6_override)
flags |= NEIGH_UPDATE_F_OVERRIDE;
if (icmph->icmp6_router)
flags |= NEIGH_UPDATE_F_ISROUTER;
ndisc_update(dev, neigh, lladdr,
icmph->icmp6_solicited ? NUD_REACHABLE : NUD_STALE,
flags, NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts);
But really, why bother?
Just because checkpatch bleats some message doesn't
mean it _has_ to be fixed.
Please strive to make the code more readable and
intelligible for _humans_. Compilers don't care.
next prev parent reply other threads:[~2017-05-21 16:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-21 0:55 [PATCH net-next v5] net: ipv6: fix code style error and warning of ndisc.c yuan linyu
2017-05-21 16:05 ` Joe Perches [this message]
2017-05-21 16:17 ` David Ahern
2017-05-21 16:54 ` David Miller
2017-05-21 21:14 ` Joe Perches
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=1495382708.2093.10.camel@perches.com \
--to=joe@perches.com \
--cc=Linyu.Yuan@alcatel-sbell.com.cn \
--cc=cugyly@163.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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).