From: Phil Sutter <phil@nwl.cc>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Jakub Sitnicki' <jkbs@redhat.com>,
Stephen Hemminger <shemming@brocade.com>,
Daniel Borkmann <daniel@iogearbox.net>,
David Ahern <dsa@cumulusnetworks.com>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Julien Floret <julien.floret@6wind.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [iproute PATCH v2 7/7] ip/tcp_metrics: Simplify process_msg a bit
Date: Wed, 22 Jun 2016 15:08:57 +0200 [thread overview]
Message-ID: <20160622130857.GC15980@orbyte.nwl.cc> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D5F4E2559@AcuExch.aculab.com>
Hi David,
On Wed, Jun 22, 2016 at 01:00:08PM +0000, David Laight wrote:
> From: Jakub Sitnicki
> > Sent: 22 June 2016 12:34
> ...
> > > - a = attrs[TCP_METRICS_ATTR_ADDR_IPV4];
> > > - if (a) {
> > > + if ((a = attrs[TCP_METRICS_ATTR_ADDR_IPV4])) {
> >
> > Copy the pointer inside the branch?
> >
> > Same gain on indentation while keeping checkpatch happy.
>
> Or as below (hacked from the mails):
>
> a = attrs[TCP_METRICS_ATTR_ADDR_IPV4];
> if (a) {
> if (f.daddr.family && f.daddr.family != AF_INET)
> return 0;
> memcpy(&daddr.data, RTA_DATA(a), 4);
> daddr.bytelen = 4;
> family = AF_INET;
> atype = TCP_METRICS_ATTR_ADDR_IPV4;
> dlen = RTA_PAYLOAD(a);
> } else {
> a = attrs[TCP_METRICS_ATTR_ADDR_IPV6];
> if (!a)
> return 0;
> memcpy(&daddr.data, RTA_DATA(a), 16);
> daddr.bytelen = 16;
> family = AF_INET6;
> atype = TCP_METRICS_ATTR_ADDR_IPV6;
> dlen = RTA_PAYLOAD(a);
> }
Yes, this should work as well and require less code changes overall.
Though I think it's less readable:
| if (a) {
| do a;
| else {
| if (!b)
| return;
| do b;
| }
vs.
| if (a) {
| do a;
| } else if (b) {
| do b;
| } else {
| return;
| }
Don't you think?
Thanks, Phil
prev parent reply other threads:[~2016-06-22 13:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 16:18 [iproute PATCH v2 0/7] Big C99 style initializer rework Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 1/7] tc: m_action: Improve conversion to C99 style initializers Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 2/7] Use C99 style initializers everywhere Phil Sutter
2016-06-21 16:24 ` David Ahern
2016-06-21 17:03 ` Phil Sutter
2016-06-21 17:13 ` David Ahern
2016-06-21 17:17 ` Phil Sutter
2016-06-21 18:30 ` Stephen Hemminger
2016-06-22 9:12 ` Jakub Sitnicki
2016-06-22 9:29 ` Phil Sutter
2016-06-22 9:41 ` Jakub Sitnicki
2016-06-21 16:18 ` [iproute PATCH v2 3/7] Replace malloc && memset by calloc Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 4/7] No need to initialize rtattr fields before parsing Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 5/7] Makefile: Allow to override CC Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 6/7] misc/ifstat: simplify unsigned value comparison Phil Sutter
2016-06-21 16:18 ` [iproute PATCH v2 7/7] ip/tcp_metrics: Simplify process_msg a bit Phil Sutter
2016-06-21 16:29 ` David Laight
2016-06-21 16:53 ` Stephen Hemminger
2016-06-21 17:07 ` Phil Sutter
2016-06-22 11:34 ` Jakub Sitnicki
2016-06-22 12:55 ` Phil Sutter
2016-06-22 13:00 ` David Laight
2016-06-22 13:08 ` Phil Sutter [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=20160622130857.GC15980@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=David.Laight@ACULAB.COM \
--cc=daniel@iogearbox.net \
--cc=dsa@cumulusnetworks.com \
--cc=jkbs@redhat.com \
--cc=julien.floret@6wind.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=shemming@brocade.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).