Skip to contentSkip to conversation

localize functions where possible

PATCH In review Stephen Hemminger 2 participants 9 messages Jun 1, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover localize functions where possible

This is the result of using a script to examine where functions are defined in one file but not used in any other file. Found some dead code in process.

Stephen Hemminger (7):
utils: make local cmdline functions static
libnetlink: drop unused rtnl_talk_iov
bridge: make print_vlan_info static
rt_names: drop unused rtnl_addrprot_a2n
ip: make print_rta_gateway static
xfrm: make xfrm_stat_print_nokeys static
rdma: make rd_attr_check static

 bridge/br_common.h   |  1 -
 bridge/vlan.c        |  3 ++-
 include/libnetlink.h |  3 ---
 include/rt_names.h   |  1 -
 include/utils.h      |  3 ---
 ip/ip_common.h       |  2 --
 ip/iproute.c         |  2 +-
 ip/xfrm.h            |  1 -
 ip/xfrm_state.c      |  2 +-
 lib/libnetlink.c     |  6 ------
 lib/rt_names.c       | 33 ---------------------------------
 lib/utils.c          |  6 +++---
 rdma/rdma.h          |  1 -
 rdma/utils.c         |  2 +-
 14 files changed, 8 insertions(+), 58 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/7 utils: make local cmdline functions static

No need to expose these parts of command line parsing.

---
 include/utils.h | 3 ---
 lib/utils.c     | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)
include/utils.h +0 -3
index 0f1b3bef34d8..0b5d86a26488 100644
@@ -139,7 +139,6 @@ int get_addr_rta(inet_prefix *dst, const struct rtattr *rta, int family);
 int get_addr_ila(__u64 *val, const char *arg);
 
 int read_prop(const char *dev, char *prop, long *value);
-int get_hex(char c);
 int get_integer(int *val, const char *arg, int base);
 int get_unsigned(unsigned *val, const char *arg, int base);
 int get_time_rtt(unsigned *val, const char *arg, int *raw);
@@ -304,8 +303,6 @@ unsigned int print_name_and_link(const char *fmt,
 #define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
 
 extern int cmdlineno;
-ssize_t getcmdline(char **line, size_t *len, FILE *in);
-int makeargs(char *line, char *argv[], int maxargs);
 
 char *int_to_str(int val, char *buf);
 int get_guid(__u64 *guid, const char *arg);
lib/utils.c +3 -3
index 8dc302bdfe02..01f3a5f7e4ea 100644
@@ -96,7 +96,7 @@ out:
 	return -1;
 }
 
-int get_hex(char c)
+static int get_hex(char c)
 {
 	if (c >= 'A' && c <= 'F')
 		return c - 'A' + 10;
@@ -1289,7 +1289,7 @@ unsigned int print_name_and_link(const char *fmt,
 int cmdlineno;
 
 /* Like glibc getline but handle continuation lines and comments */
-ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
+static ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
 {
 	ssize_t cc;
 	char *cp;
@@ -1336,7 +1336,7 @@ ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
 }
 
 /* split command line into argument vector */
-int makeargs(char *line, char *argv[], int maxargs)
+static int makeargs(char *line, char *argv[], int maxargs)
 {
 	static const char ws[] = " \t\r\n";
 	char *cp = line;
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/7 libnetlink: drop unused rtnl_talk_iov

In reply to Stephen Hemminger

Function was defined but not used in current iproute2 code.

---
 include/libnetlink.h | 3 ---
 lib/libnetlink.c     | 6 ------
 2 files changed, 9 deletions(-)
include/libnetlink.h +0 -3
index c91a22314548..39ed87a7976e 100644
@@ -177,9 +177,6 @@ int rtnl_echo_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, int json,
 int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 	      struct nlmsghdr **answer)
 	__attribute__((warn_unused_result));
-int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
-		  struct nlmsghdr **answer)
-	__attribute__((warn_unused_result));
 int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 				   struct nlmsghdr **answer)
 	__attribute__((warn_unused_result));
lib/libnetlink.c +0 -6
index 68360b0f4c96..7edcd28569fd 100644
@@ -1168,12 +1168,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 	return __rtnl_talk(rtnl, n, answer, true, NULL);
 }
 
-int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
-		  struct nlmsghdr **answer)
-{
-	return __rtnl_talk_iov(rtnl, iovec, iovlen, answer, true, NULL);
-}
-
 int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 				   struct nlmsghdr **answer)
 {
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/7 bridge: make print_vlan_info static

In reply to Stephen Hemminger

Function defined and used in only one file.

---
 bridge/br_common.h | 1 -
 bridge/vlan.c      | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)
bridge/br_common.h +0 -1
index 1bdee65844c1..704e76b0acb2 100644
@@ -6,7 +6,6 @@
 #define MDB_RTR_RTA(r) \
 		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
 
-void print_vlan_info(struct rtattr *tb, int ifindex);
 int print_linkinfo(struct nlmsghdr *n, void *arg);
 int print_mdb_mon(struct nlmsghdr *n, void *arg);
 int print_fdb(struct nlmsghdr *n, void *arg);
bridge/vlan.c +2 -1
index 5b304ea94224..dfc62f83a5df 100644
@@ -18,6 +18,7 @@
 
 static unsigned int filter_index, filter_vlan;
 static int vlan_rtm_cur_ifidx = -1;
+static void print_vlan_info(struct rtattr *tb, int ifindex);
 
 enum vlan_show_subject {
 	VLAN_SHOW_VLAN,
@@ -1309,7 +1310,7 @@ static int vlan_global_show(int argc, char **argv)
 	return 0;
 }
 
-void print_vlan_info(struct rtattr *tb, int ifindex)
+static void print_vlan_info(struct rtattr *tb, int ifindex)
 {
 	struct rtattr *i, *list = tb;
 	int rem = RTA_PAYLOAD(list);
Signature · 1 line
2.39.2
maintainer Acked-by on v1 3/7
#4 lore raw

Re: [PATCH iproute2 3/7] bridge: make print_vlan_info static

Quoted 33 lines · Stephen Hemminger

Function defined and used in only one file.

---
 bridge/br_common.h | 1 -
 bridge/vlan.c      | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)
bridge/br_common.h +0 -1
index 1bdee65844c1..704e76b0acb2 100644
@@ -6,7 +6,6 @@
 #define MDB_RTR_RTA(r) \
 		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
 
-void print_vlan_info(struct rtattr *tb, int ifindex);
 int print_linkinfo(struct nlmsghdr *n, void *arg);
 int print_mdb_mon(struct nlmsghdr *n, void *arg);
 int print_fdb(struct nlmsghdr *n, void *arg);
bridge/vlan.c +1 -0
index 5b304ea94224..dfc62f83a5df 100644
@@ -18,6 +18,7 @@
 
 static unsigned int filter_index, filter_vlan;
 static int vlan_rtm_cur_ifidx = -1;
+static void print_vlan_info(struct rtattr *tb, int ifindex);
 
 enum vlan_show_subject {
 	VLAN_SHOW_VLAN,

bridge/vlan.c static int vlan_global_show(int argc, char **argv) · line 1316

Quoted 8 lines
bridge/vlan.c +1 -1
@@ -1309,7 +1310,7 @@ static int vlan_global_show(int argc, char **argv)
 	return 0;
 }
 
-void print_vlan_info(struct rtattr *tb, int ifindex)
+static void print_vlan_info(struct rtattr *tb, int ifindex)
 {
 	struct rtattr *i, *list = tb;
 	int rem = RTA_PAYLOAD(list);

Thanks,

#5 lore raw

PATCH 4/7 rt_names: drop unused rtnl_addrprot_a2n

In reply to Stephen Hemminger

This function is defined but never used in current code.

---
 include/rt_names.h |  1 -
 lib/rt_names.c     | 33 ---------------------------------
 2 files changed, 34 deletions(-)
include/rt_names.h +0 -1
index e96d80f30554..9003e67785b3 100644
@@ -14,7 +14,6 @@ const char *rtnl_dsfield_get_name(int id);
 const char *rtnl_group_n2a(int id, char *buf, int len);
 
 int rtnl_rtprot_a2n(__u32 *id, const char *arg);
-int rtnl_addrprot_a2n(__u32 *id, const char *arg);
 int rtnl_rtscope_a2n(__u32 *id, const char *arg);
 int rtnl_rttable_a2n(__u32 *id, const char *arg);
 int rtnl_rtrealm_a2n(__u32 *id, const char *arg);
lib/rt_names.c +0 -33
index 51d11fd056b1..8af3bca3245b 100644
@@ -255,39 +255,6 @@ numeric:
 	return buf;
 }
 
-int rtnl_addrprot_a2n(__u32 *id, const char *arg)
-{
-	static char *cache;
-	static unsigned long res;
-	char *end;
-	int i;
-
-	if (cache && strcmp(cache, arg) == 0) {
-		*id = res;
-		return 0;
-	}
-
-	if (!rtnl_addrprot_tab_initialized)
-		rtnl_addrprot_initialize();
-
-	for (i = 0; i < 256; i++) {
-		if (rtnl_addrprot_tab[i] &&
-		    strcmp(rtnl_addrprot_tab[i], arg) == 0) {
-			cache = rtnl_addrprot_tab[i];
-			res = i;
-			*id = res;
-			return 0;
-		}
-	}
-
-	res = strtoul(arg, &end, 0);
-	if (!end || end == arg || *end || res > 255)
-		return -1;
-	*id = res;
-	return 0;
-}
-
-
 static char *rtnl_rtscope_tab[256] = {
 	[RT_SCOPE_UNIVERSE]	= "global",
 	[RT_SCOPE_NOWHERE]	= "nowhere",
Signature · 1 line
2.39.2
#6 lore raw

PATCH 5/7 ip: make print_rta_gateway static

In reply to Stephen Hemminger

Function only used in one file.

---
 ip/ip_common.h | 2 --
 ip/iproute.c   | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
ip/ip_common.h +0 -2
index 4a20ec3cba62..b65c2b41dc87 100644
@@ -226,8 +226,6 @@ void print_num(FILE *fp, unsigned int width, uint64_t count);
 void print_rt_flags(FILE *fp, unsigned int flags);
 void print_rta_ifidx(FILE *fp, __u32 ifidx, const char *prefix);
 void __print_rta_gateway(FILE *fp, unsigned char family, const char *gateway);
-void print_rta_gateway(FILE *fp, unsigned char family,
-		       const struct rtattr *rta);
 void size_columns(unsigned int cols[], unsigned int n, ...);
 void print_stats64(FILE *fp, struct rtnl_link_stats64 *s,
 		   const struct rtattr *carrier_changes, const char *what);
ip/iproute.c +1 -1
index 7909c4a210cc..fdf1f9a9dd0a 100644
@@ -558,7 +558,7 @@ void __print_rta_gateway(FILE *fp, unsigned char family, const char *gateway)
 	}
 }
 
-void print_rta_gateway(FILE *fp, unsigned char family, const struct rtattr *rta)
+static void print_rta_gateway(FILE *fp, unsigned char family, const struct rtattr *rta)
 {
 	const char *gateway = format_host_rta(family, rta);
 
Signature · 1 line
2.39.2
#7 lore raw

PATCH 6/7 xfrm: make xfrm_stat_print_nokeys static

In reply to Stephen Hemminger

This function is only used in one file.

---
 ip/xfrm.h       | 1 -
 ip/xfrm_state.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
ip/xfrm.h +0 -1
index 33c42730375d..5238fc8b2b88 100644
@@ -90,7 +90,6 @@ struct xfrm_filter {
 extern struct xfrm_filter filter;
 
 int xfrm_state_print(struct nlmsghdr *n, void *arg);
-int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg);
 int xfrm_policy_print(struct nlmsghdr *n, void *arg);
 int do_xfrm_state(int argc, char **argv);
 int do_xfrm_policy(int argc, char **argv);
ip/xfrm_state.c +1 -1
index aa0dce072dff..a7b3d0e14156 100644
@@ -1027,7 +1027,7 @@ int xfrm_state_print(struct nlmsghdr *n, void *arg)
 	return __do_xfrm_state_print(n, arg, false);
 }
 
-int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg)
+static int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg)
 {
 	return __do_xfrm_state_print(n, arg, true);
 }
Signature · 1 line
2.39.2
#8 lore raw

PATCH 7/7 rdma: make rd_attr_check static

In reply to Stephen Hemminger

Function defined and used in only one file.

---
 rdma/rdma.h  | 1 -
 rdma/utils.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
rdma/rdma.h +0 -1
index 8b421db807a6..0bf77f4dcf9e 100644
@@ -131,7 +131,6 @@ int rd_sendrecv_msg(struct rd *rd, unsigned int seq);
 void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
 int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
 int rd_attr_cb(const struct nlattr *attr, void *data);
-int rd_attr_check(const struct nlattr *attr, int *typep);
 
 /*
  * Print helpers
rdma/utils.c +1 -1
index a33ff420f8cb..8a091c05e0a2 100644
@@ -475,7 +475,7 @@ static const enum mnl_attr_data_type nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
 	[RDMA_NLDEV_ATTR_RES_RAW] = MNL_TYPE_BINARY,
 };
 
-int rd_attr_check(const struct nlattr *attr, int *typep)
+static int rd_attr_check(const struct nlattr *attr, int *typep)
 {
 	int type;
 
Signature · 1 line
2.39.2