The following commit has been merged in the master branch: commit ec4f76bcd74b0d95e088c7942127a93d178f47fe Author: Andy Shevchenko andy.shevchenko@gmail.com Date: Sat Oct 23 12:11:54 2010 +0000
batman-adv: remove useless addr_to_string()
Since all *printf() methods in the kernel understand '%pM' modifier the conversion to the string is useless beforehand.
Additionally this patch decreases batman_if structure by 20 bytes.
Signed-off-by: Andy Shevchenko andy.shevchenko@gmail.com [sven.eckelmann@gmx.de: Fix compilation errors] Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de
diff --git a/gateway_client.c b/gateway_client.c index ae1ab1e..77f1044 100644 --- a/gateway_client.c +++ b/gateway_client.c @@ -351,17 +351,14 @@ static int _write_buffer_text(struct bat_priv *bat_priv, struct seq_file *seq, struct gw_node *gw_node) { int down, up; - char gw_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
- addr_to_string(gw_str, gw_node->orig_node->orig); - addr_to_string(router_str, gw_node->orig_node->router->addr); gw_srv_class_to_kbit(gw_node->orig_node->gw_flags, &down, &up);
- return seq_printf(seq, "%s %-17s (%3i) %17s [%10s]: %3i - %i%s/%i%s\n", + return seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n", (bat_priv->curr_gw == gw_node ? "=>" : " "), - gw_str, + gw_node->orig_node->orig, gw_node->orig_node->router->tq_avg, - router_str, + gw_node->orig_node->router->addr, gw_node->orig_node->router->if_incoming->net_dev->name, gw_node->orig_node->gw_flags, (down > 2048 ? down / 1024 : down), @@ -393,11 +390,11 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset) }
seq_printf(seq, " %-12s (%s/%i) %17s [%10s]: gw_class ... " - "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n", + "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%pM (%s)]\n", "Gateway", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", SOURCE_VERSION, REVISION_VERSION_STR, bat_priv->primary_if->net_dev->name, - bat_priv->primary_if->addr_str, net_dev->name); + bat_priv->primary_if->net_dev->dev_addr, net_dev->name);
rcu_read_lock(); hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) { diff --git a/hard-interface.c b/hard-interface.c index 3c59209..ef95680 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -171,8 +171,6 @@ static bool hardif_is_iface_up(struct batman_if *batman_if)
static void update_mac_addresses(struct batman_if *batman_if) { - addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr); - memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig, batman_if->net_dev->dev_addr, ETH_ALEN); memcpy(((struct batman_packet *)(batman_if->packet_buff))->prev_sender, diff --git a/main.c b/main.c index 9c14832..73d2752 100644 --- a/main.c +++ b/main.c @@ -154,11 +154,6 @@ void dec_module_count(void) module_put(THIS_MODULE); }
-int addr_to_string(char *buff, uint8_t *addr) -{ - return sprintf(buff, "%pM", addr); -} - int is_my_mac(uint8_t *addr) { struct batman_if *batman_if; diff --git a/main.h b/main.h index b305f55..46d9652 100644 --- a/main.h +++ b/main.h @@ -56,7 +56,6 @@
#define PACKBUFF_SIZE 2000 #define LOG_BUF_LEN 8192 /* has to be a power of 2 */ -#define ETH_STR_LEN 20
#define VIS_INTERVAL 5000 /* 5 seconds */
@@ -136,7 +135,6 @@ int mesh_init(struct net_device *soft_iface); void mesh_free(struct net_device *soft_iface); void inc_module_count(void); void dec_module_count(void); -int addr_to_string(char *buff, uint8_t *addr); int is_my_mac(uint8_t *addr); int is_bcast(uint8_t *addr); int is_mcast(uint8_t *addr); diff --git a/originator.c b/originator.c index afac4eb..3a7c5fd 100644 --- a/originator.c +++ b/originator.c @@ -332,7 +332,6 @@ int orig_seq_print_text(struct seq_file *seq, void *offset) int last_seen_secs; int last_seen_msecs; unsigned long flags; - char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
if ((!bat_priv->primary_if) || (bat_priv->primary_if->if_status != IF_ACTIVE)) { @@ -346,10 +345,10 @@ int orig_seq_print_text(struct seq_file *seq, void *offset) net_dev->name); }
- seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)]\n", + seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%pM (%s)]\n", SOURCE_VERSION, REVISION_VERSION_STR, bat_priv->primary_if->net_dev->name, - bat_priv->primary_if->addr_str, net_dev->name); + bat_priv->primary_if->net_dev->dev_addr, net_dev->name); seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n", "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", "Potential nexthops"); @@ -366,21 +365,18 @@ int orig_seq_print_text(struct seq_file *seq, void *offset) if (orig_node->router->tq_avg == 0) continue;
- addr_to_string(orig_str, orig_node->orig); - addr_to_string(router_str, orig_node->router->addr); last_seen_secs = jiffies_to_msecs(jiffies - orig_node->last_valid) / 1000; last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_valid) % 1000;
- seq_printf(seq, "%-17s %4i.%03is (%3i) %17s [%10s]:", - orig_str, last_seen_secs, last_seen_msecs, - orig_node->router->tq_avg, router_str, + seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", + orig_node->orig, last_seen_secs, last_seen_msecs, + orig_node->router->tq_avg, orig_node->router->addr, orig_node->router->if_incoming->net_dev->name);
list_for_each_entry(neigh_node, &orig_node->neigh_list, list) { - addr_to_string(orig_str, neigh_node->addr); - seq_printf(seq, " %17s (%3i)", orig_str, + seq_printf(seq, " %pM (%3i)", neigh_node->addr, neigh_node->tq_avg); }
diff --git a/routing.c b/routing.c index 186428d..80fb16d 100644 --- a/routing.c +++ b/routing.c @@ -568,11 +568,11 @@ void receive_bat_packet(struct ethhdr *ethhdr, batman_packet->orig) ? 1 : 0);
bat_dbg(DBG_BATMAN, bat_priv, - "Received BATMAN packet via NB: %pM, IF: %s [%s] " + "Received BATMAN packet via NB: %pM, IF: %s [%pM] " "(from OG: %pM, via prev OG: %pM, seqno %d, tq %d, " "TTL %d, V %d, IDF %d)\n", ethhdr->h_source, if_incoming->net_dev->name, - if_incoming->addr_str, batman_packet->orig, + if_incoming->net_dev->dev_addr, batman_packet->orig, batman_packet->prev_sender, batman_packet->seqno, batman_packet->tq, batman_packet->ttl, batman_packet->version, has_directlink_flag); diff --git a/send.c b/send.c index a6cb644..7a1e590 100644 --- a/send.c +++ b/send.c @@ -139,13 +139,13 @@ static void send_packet_to_if(struct forw_packet *forw_packet, "Forwarding")); bat_dbg(DBG_BATMAN, bat_priv, "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d," - " IDF %s) on interface %s [%s]\n", + " IDF %s) on interface %s [%pM]\n", fwd_str, (packet_num > 0 ? "aggregated " : ""), batman_packet->orig, ntohl(batman_packet->seqno), batman_packet->tq, batman_packet->ttl, (batman_packet->flags & DIRECTLINK ? "on" : "off"), - batman_if->net_dev->name, batman_if->addr_str); + batman_if->net_dev->name, batman_if->net_dev->dev_addr);
buff_pos += sizeof(struct batman_packet) + (batman_packet->num_hna * ETH_ALEN); @@ -190,12 +190,12 @@ static void send_packet(struct forw_packet *forw_packet) /* FIXME: what about aggregated packets ? */ bat_dbg(DBG_BATMAN, bat_priv, "%s packet (originator %pM, seqno %d, TTL %d) " - "on interface %s [%s]\n", + "on interface %s [%pM]\n", (forw_packet->own ? "Sending own" : "Forwarding"), batman_packet->orig, ntohl(batman_packet->seqno), batman_packet->ttl, forw_packet->if_incoming->net_dev->name, - forw_packet->if_incoming->addr_str); + forw_packet->if_incoming->net_dev->dev_addr);
/* skb is only used once and than forw_packet is free'd */ send_skb_packet(forw_packet->skb, forw_packet->if_incoming, diff --git a/types.h b/types.h index 299769e..2678ce1 100644 --- a/types.h +++ b/types.h @@ -37,7 +37,6 @@ struct batman_if { struct list_head list; int16_t if_num; char if_status; - char addr_str[ETH_STR_LEN]; struct net_device *net_dev; atomic_t seqno; atomic_t frag_seqno; diff --git a/vis.c b/vis.c index 9e41f81..13573d5 100644 --- a/vis.c +++ b/vis.c @@ -132,15 +132,13 @@ static ssize_t vis_data_read_prim_sec(char *buff, struct hlist_head *if_list) { struct if_list_entry *entry; struct hlist_node *pos; - char tmp_addr_str[ETH_STR_LEN]; size_t len = 0;
hlist_for_each_entry(entry, pos, if_list, list) { if (entry->primary) len += sprintf(buff + len, "PRIMARY, "); else { - addr_to_string(tmp_addr_str, entry->addr); - len += sprintf(buff + len, "SEC %s, ", tmp_addr_str); + len += sprintf(buff + len, "SEC %pM, ", entry->addr); } }
@@ -167,14 +165,12 @@ static size_t vis_data_count_prim_sec(struct hlist_head *if_list) static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry, uint8_t *src, bool primary) { - char to[18]; - /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */ - addr_to_string(to, entry->dest); if (primary && entry->quality == 0) - return sprintf(buff, "HNA %s, ", to); + return sprintf(buff, "HNA %pM, ", entry->dest); else if (compare_orig(entry->src, src)) - return sprintf(buff, "TQ %s %d, ", to, entry->quality); + return sprintf(buff, "TQ %pM %d, ", entry->dest, + entry->quality);
return 0; } @@ -193,7 +189,6 @@ int vis_seq_print_text(struct seq_file *seq, void *offset) struct if_list_entry *entry; struct hlist_node *pos, *n; int i; - char tmp_addr_str[ETH_STR_LEN]; unsigned long flags; int vis_server = atomic_read(&bat_priv->vis_mode); size_t buff_pos, buf_size; @@ -261,9 +256,8 @@ int vis_seq_print_text(struct seq_file *seq, void *offset) }
hlist_for_each_entry(entry, pos, &vis_if_list, list) { - addr_to_string(tmp_addr_str, entry->addr); - buff_pos += sprintf(buff + buff_pos, "%s,", - tmp_addr_str); + buff_pos += sprintf(buff + buff_pos, "%pM,", + entry->addr);
for (i = 0; i < packet->entries; i++) buff_pos += vis_data_read_entry(buff + buff_pos,