From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next v5 5/9] ipaddress: Simplify print_linkinfo_brief() and it's usage Date: Thu, 15 Feb 2018 23:23:20 +0200 Message-ID: <1518729804-19873-6-git-send-email-serhe.popovych@gmail.com> References: <1518729804-19873-1-git-send-email-serhe.popovych@gmail.com> Cc: dsahern@gmail.com To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f66.google.com ([209.85.215.66]:37126 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162366AbeBOVX7 (ORCPT ); Thu, 15 Feb 2018 16:23:59 -0500 Received: by mail-lf0-f66.google.com with SMTP id f137so1481456lfe.4 for ; Thu, 15 Feb 2018 13:23:58 -0800 (PST) In-Reply-To: <1518729804-19873-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Simplify calling code in ipaddr_list_flush_or_save() by introducing intermediate variable of @struct nlmsghdr, drop duplicated code: print_linkinfo_brief() never returns values other than <= 0 so we can move print_selected_addrinfo() outside of each block. Signed-off-by: Serhey Popovych --- ip/ipaddress.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 6eac370..749178d 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -753,7 +753,7 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n) } int print_linkinfo_brief(const struct sockaddr_nl *who, - struct nlmsghdr *n, void *arg) + struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; struct ifinfomsg *ifi = NLMSG_DATA(n); @@ -2013,24 +2013,21 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) ipaddr_filter(&linfo, ainfo); for (l = linfo.head; l; l = l->next) { - int res = 0; - struct ifinfomsg *ifi = NLMSG_DATA(&l->h); + struct nlmsghdr *n = &l->h; + struct ifinfomsg *ifi = NLMSG_DATA(n); + int res; open_json_object(NULL); - if (brief) { - if (print_linkinfo_brief(NULL, &l->h, stdout) == 0) - if (filter.family != AF_PACKET) - print_selected_addrinfo(ifi, - ainfo->head, - stdout); - } else if (no_link || - (res = print_linkinfo(NULL, &l->h, stdout)) >= 0) { - if (filter.family != AF_PACKET) - print_selected_addrinfo(ifi, - ainfo->head, stdout); - if (res > 0 && !do_link && show_stats) - print_link_stats(stdout, &l->h); - } + if (brief) + res = print_linkinfo_brief(NULL, n, stdout); + else if (no_link) + res = 0; + else + res = print_linkinfo(NULL, n, stdout); + if (res >= 0 && filter.family != AF_PACKET) + print_selected_addrinfo(ifi, ainfo->head, stdout); + if (res > 0 && !do_link && show_stats) + print_link_stats(stdout, n); close_json_object(); } fflush(stdout); -- 1.7.10.4