From patchwork Thu Jun 3 14:44:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 211 Return-Path: Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by open-mesh.net (Postfix) with SMTP id DC1BA154169 for ; Thu, 3 Jun 2010 16:44:11 +0200 (CEST) Received: (qmail invoked by alias); 03 Jun 2010 14:44:10 -0000 Received: from unknown (EHLO sven-desktop.lazhur.ath.cx) [89.246.223.58] by mail.gmx.net (mp044) with SMTP; 03 Jun 2010 16:44:10 +0200 X-Authenticated: #15668376 X-Provags-ID: V01U2FsdGVkX18dTzB5YU4dt/AhIJnypJWXtU372TNjhnNwW1ZRFO cCmvaTWFJo7iTu From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.net Date: Thu, 3 Jun 2010 16:44:05 +0200 Message-Id: <1275576246-29381-1-git-send-email-sven.eckelmann@gmx.de> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1275575978-29121-1-git-send-email-sven.eckelmann@gmx.de> References: <1275575978-29121-1-git-send-email-sven.eckelmann@gmx.de> X-Y-GMX-Trusted: 0 Cc: Joe Perches Subject: [B.A.T.M.A.N.] [PATCH-maint] drivers/staging/batman-adv: Convert MAC_FMT to %pM X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2010 14:44:12 -0000 From: Joe Perches Remove the last uses of MAC_FMT Signed-off-by: Joe Perches [sven.eckelmann@gmx.de: Adapted for current batman-adv version] Signed-off-by: Sven Eckelmann --- Marek, please check with your 2.6.21 nodes if it works (just did some quick tests). bat_printk.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ compat.h | 12 ++++++------ main.c | 3 +-- translation-table.c | 24 ++++-------------------- 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/bat_printk.c b/bat_printk.c index 55c351a..4a02d7e 100644 --- a/bat_printk.c +++ b/bat_printk.c @@ -859,3 +859,53 @@ asmlinkage int bat_printk(const char *fmt, ...) return printk("%s", buf); } + +/** + * sprintf - Format a string and place it in a buffer + * @buf: The buffer to place the result into + * @fmt: The format string to use + * @...: Arguments for the format string + * + * The function returns the number of characters written + * into @buf. Use snprintf() or scnprintf() in order to avoid + * buffer overflows. + * + * See the vsnprintf() documentation for format string extensions over C99. + */ +int bat_sprintf(char *buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i = bat_vsnprintf(buf, INT_MAX, fmt, args); + va_end(args); + + return i; +} + +/** + * snprintf - Format a string and place it in a buffer + * @buf: The buffer to place the result into + * @size: The size of the buffer, including the trailing null space + * @fmt: The format string to use + * @...: Arguments for the format string + * + * The return value is the number of characters which would be + * generated for the given input, excluding the trailing null, + * as per ISO C99. If the return is greater than or equal to + * @size, the resulting string is truncated. + * + * See the vsnprintf() documentation for format string extensions over C99. + */ +int bat_snprintf(char *buf, size_t size, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i = bat_vsnprintf(buf, size, fmt, args); + va_end(args); + + return i; +} diff --git a/compat.h b/compat.h index ae967aa..144e25a 100644 --- a/compat.h +++ b/compat.h @@ -70,12 +70,6 @@ static inline int skb_clone_writable(struct sk_buff *skb, unsigned int len) #endif /* < KERNEL_VERSION(2, 6, 23) */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) - -#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" - -#endif /* < KERNEL_VERSION(2, 6, 24) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) #define strict_strtoul(cp, base, res) \ @@ -231,6 +225,12 @@ next_sibling: asmlinkage int bat_printk(const char *fmt, ...); #define printk bat_printk +int bat_sprintf(char *buf, const char *fmt, ...); +#define sprintf bat_sprintf + +int bat_snprintf(char *buf, size_t size, const char *fmt, ...); +#define snprintf bat_snprintf + static inline struct net_device_stats *dev_get_stats(struct net_device *dev) { if (dev->get_stats) diff --git a/main.c b/main.c index d9c6ec7..05744e7 100644 --- a/main.c +++ b/main.c @@ -231,8 +231,7 @@ void dec_module_count(void) int addr_to_string(char *buff, uint8_t *addr) { - return sprintf(buff, MAC_FMT, - addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); + return sprintf(buff, "%pM", addr); } /* returns 1 if they are the same originator */ diff --git a/translation-table.c b/translation-table.c index 009789e..8edc175 100644 --- a/translation-table.c +++ b/translation-table.c @@ -200,13 +200,8 @@ int hna_local_seq_print_text(struct seq_file *seq, void *offset) while (hash_iterate(hna_local_hash, &hashit)) { hna_local_entry = hashit.bucket->data; - pos += snprintf(buff + pos, 22, " * " MAC_FMT "\n", - hna_local_entry->addr[0], - hna_local_entry->addr[1], - hna_local_entry->addr[2], - hna_local_entry->addr[3], - hna_local_entry->addr[4], - hna_local_entry->addr[5]); + pos += snprintf(buff + pos, 22, " * %pM\n", + hna_local_entry->addr); } spin_unlock_irqrestore(&hna_local_hash_lock, flags); @@ -418,19 +413,8 @@ int hna_global_seq_print_text(struct seq_file *seq, void *offset) hna_global_entry = hashit.bucket->data; pos += snprintf(buff + pos, 44, - " * " MAC_FMT " via " MAC_FMT "\n", - hna_global_entry->addr[0], - hna_global_entry->addr[1], - hna_global_entry->addr[2], - hna_global_entry->addr[3], - hna_global_entry->addr[4], - hna_global_entry->addr[5], - hna_global_entry->orig_node->orig[0], - hna_global_entry->orig_node->orig[1], - hna_global_entry->orig_node->orig[2], - hna_global_entry->orig_node->orig[3], - hna_global_entry->orig_node->orig[4], - hna_global_entry->orig_node->orig[5]); + " * %pM via %pM\n", hna_global_entry->addr, + hna_global_entry->orig_node->orig); } spin_unlock_irqrestore(&hna_global_hash_lock, flags);