From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next 2/9] ipaddress: ll_map: Replace ll_idx_n2a() with ll_index_to_name() Date: Mon, 5 Feb 2018 21:49:27 +0200 Message-ID: <1517860174-18333-3-git-send-email-serhe.popovych@gmail.com> References: <1517860174-18333-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f66.google.com ([209.85.215.66]:38496 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751089AbeBETuN (ORCPT ); Mon, 5 Feb 2018 14:50:13 -0500 Received: by mail-lf0-f66.google.com with SMTP id g72so43411688lfg.5 for ; Mon, 05 Feb 2018 11:50:13 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id h39sm1941284lji.72.2018.02.05.11.50.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 11:50:10 -0800 (PST) In-Reply-To: <1517860174-18333-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: There is no reentrancy as well as deferred result usage for all cases where ll_idx_n2a() being used: it is safe to use ll_index_to_name() that internally calls ll_idx_n2a() with static buffer to hold result. Signed-off-by: Serhey Popovych --- ip/ipaddress.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 38ef5d7..366a304 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -978,14 +978,13 @@ int print_linkinfo_brief(const struct sockaddr_nl *who, print_bool(PRINT_ANY, "deleted", "Deleted ", true); if (tb[IFLA_LINK]) { - SPRINT_BUF(b1); int iflink = rta_getattr_u32(tb[IFLA_LINK]); if (iflink == 0) { snprintf(buf, sizeof(buf), "%s@NONE", name); print_null(PRINT_JSON, "link", NULL, NULL); } else { - const char *link = ll_idx_n2a(iflink, b1); + const char *link = ll_index_to_name(iflink); print_string(PRINT_JSON, "link", NULL, link); snprintf(buf, sizeof(buf), "%s@%s", name, link); @@ -1122,12 +1121,10 @@ int print_linkinfo(const struct sockaddr_nl *who, print_int(PRINT_ANY, "link_index", "@if%d: ", iflink); else { - SPRINT_BUF(b1); - print_string(PRINT_ANY, "link", "@%s: ", - ll_idx_n2a(iflink, b1)); + ll_index_to_name(iflink)); m_flag = ll_index_to_flags(iflink); m_flag = !(m_flag & IFF_UP); } @@ -1149,12 +1146,12 @@ int print_linkinfo(const struct sockaddr_nl *who, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC])); if (tb[IFLA_MASTER]) { - SPRINT_BUF(b1); + int master = rta_getattr_u32(tb[IFLA_MASTER]); print_string(PRINT_ANY, "master", "master %s ", - ll_idx_n2a(rta_getattr_u32(tb[IFLA_MASTER]), b1)); + ll_index_to_name(master)); } if (tb[IFLA_OPERSTATE]) @@ -1473,7 +1470,6 @@ static int get_filter(const char *arg) static int ifa_label_match_rta(int ifindex, const struct rtattr *rta) { const char *label; - SPRINT_BUF(b1); if (!filter.label) return 0; @@ -1481,7 +1477,7 @@ static int ifa_label_match_rta(int ifindex, const struct rtattr *rta) if (rta) label = RTA_DATA(rta); else - label = ll_idx_n2a(ifindex, b1); + label = ll_index_to_name(ifindex); return fnmatch(filter.label, label, 0); } -- 1.7.10.4