b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
@ 2010-06-02 20:10 Joe Perches
  2010-06-02 23:23 ` Sven Eckelmann
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Joe Perches @ 2010-06-02 20:10 UTC (permalink / raw)
  To: Marek Lindner, Simon Wunderlich, Andrew Lunn, Greg Kroah-Hartman
  Cc: devel, b.a.t.m.a.n, linux-kernel

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/staging/batman-adv/main.c              |    3 +-
 drivers/staging/batman-adv/translation-table.c |   25 ++++-------------------
 2 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/batman-adv/main.c b/drivers/staging/batman-adv/main.c
index 74c70d5..72851cd 100644
--- a/drivers/staging/batman-adv/main.c
+++ b/drivers/staging/batman-adv/main.c
@@ -226,8 +226,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/drivers/staging/batman-adv/translation-table.c b/drivers/staging/batman-adv/translation-table.c
index e01ff21..63d0967 100644
--- a/drivers/staging/batman-adv/translation-table.c
+++ b/drivers/staging/batman-adv/translation-table.c
@@ -202,13 +202,8 @@ int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff,
 		hna_local_entry = hashit.bucket->data;
 
 		bytes_written += snprintf(buff + bytes_written, 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]);
+					  " * %pM\n",
+					  hna_local_entry->addr);
 	}
 
 	spin_unlock_irqrestore(&hna_local_hash_lock, flags);
@@ -420,19 +415,9 @@ int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff,
 		hna_global_entry = hashit.bucket->data;
 
 		bytes_written += snprintf(buff + bytes_written, 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);




^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 20:10 [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM Joe Perches
@ 2010-06-02 23:23 ` Sven Eckelmann
  2010-06-02 23:32   ` Joe Perches
  2010-06-03 13:58 ` Sven Eckelmann
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-02 23:23 UTC (permalink / raw)
  To: b.a.t.m.a.n
  Cc: devel, b.a.t.m.a.n, Greg Kroah-Hartman, linux-kernel,
	Simon Wunderlich, Joe Perches, Marek Lindner

[-- Attachment #1: Type: Text/Plain, Size: 1536 bytes --]

Joe Perches wrote:
> Remove the last uses of MAC_FMT
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  drivers/staging/batman-adv/main.c              |    3 +-
>  drivers/staging/batman-adv/translation-table.c |   25
> ++++------------------- 2 files changed, 6 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/staging/batman-adv/main.c
> b/drivers/staging/batman-adv/main.c index 74c70d5..72851cd 100644
> --- a/drivers/staging/batman-adv/main.c
> +++ b/drivers/staging/batman-adv/main.c
> @@ -226,8 +226,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);
>  }
[...]

Thanks for your patch.

We must currently support older kernels which doesn't support %pM. Thats why 
we have an extra wrapper for printk in the out-of-kernel module. The same 
would have to be done for sprintf as well. Most of the developers are 
currently attending the Wireless Battle Mesh v3 - so the processing of that 
patch is delayed a little bit.

The same problem arises with your patch "Use (pr|netdev)_<level> macro helper" 
(which seems to be added in 2.6.34). But I think we could add a wrapper for 
older kernels easily - but as mentioned before this is probably postponed 
until next week or so.

You've also changed the output. So you may partly broke batctl too (have to 
check that first).

Best regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 23:23 ` Sven Eckelmann
@ 2010-06-02 23:32   ` Joe Perches
  2010-06-02 23:33     ` Sven Eckelmann
  0 siblings, 1 reply; 17+ messages in thread
From: Joe Perches @ 2010-06-02 23:32 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: devel, Greg Kroah-Hartman, b.a.t.m.a.n, b.a.t.m.a.n,
	linux-kernel, Simon Wunderlich, Marek Lindner

On Thu, 2010-06-03 at 01:23 +0200, Sven Eckelmann wrote:
> You've also changed the output. So you may partly broke batctl too (have to 
> check that first).

There was no change in output.
MAC_FMT output is the same as %pM

cheers, Joe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 23:32   ` Joe Perches
@ 2010-06-02 23:33     ` Sven Eckelmann
  2010-06-02 23:47       ` Joe Perches
  0 siblings, 1 reply; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-02 23:33 UTC (permalink / raw)
  To: Joe Perches
  Cc: devel, Greg Kroah-Hartman, b.a.t.m.a.n, b.a.t.m.a.n,
	linux-kernel, Simon Wunderlich, Marek Lindner

[-- Attachment #1: Type: Text/Plain, Size: 314 bytes --]

Joe Perches wrote:
> On Thu, 2010-06-03 at 01:23 +0200, Sven Eckelmann wrote:
> > You've also changed the output. So you may partly broke batctl too (have
> > to check that first).
> 
> There was no change in output.
> MAC_FMT output is the same as %pM

I meant the other patch :)

Best regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 23:33     ` Sven Eckelmann
@ 2010-06-02 23:47       ` Joe Perches
  2010-06-02 23:56         ` Sven Eckelmann
  0 siblings, 1 reply; 17+ messages in thread
From: Joe Perches @ 2010-06-02 23:47 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: devel, Greg Kroah-Hartman, b.a.t.m.a.n, b.a.t.m.a.n,
	linux-kernel, Simon Wunderlich, Marek Lindner

On Thu, 2010-06-03 at 01:33 +0200, Sven Eckelmann wrote:
> Joe Perches wrote:
> > On Thu, 2010-06-03 at 01:23 +0200, Sven Eckelmann wrote:
> > > You've also changed the output. So you may partly broke batctl too (have
> > > to check that first).
> > There was no change in output.
> > MAC_FMT output is the same as %pM
> I meant the other patch :)

batctl is parsing dmesg or equivalent?  ouch.

If so, may I suggest you consider using something other than
a message logging parser for batctl?

I glanced at the source and don't see any such use.
It looks like it's only /sys, /proc and debugfs,
but I only spent a few seconds at it.

http://www.open-mesh.net/changeset/1682/trunk?old_path=%2F&format=zip

cheers, Joe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 23:47       ` Joe Perches
@ 2010-06-02 23:56         ` Sven Eckelmann
  2010-06-03  0:20           ` Joe Perches
  0 siblings, 1 reply; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-02 23:56 UTC (permalink / raw)
  To: Joe Perches
  Cc: devel, Greg Kroah-Hartman, b.a.t.m.a.n, b.a.t.m.a.n,
	linux-kernel, Simon Wunderlich, Marek Lindner

[-- Attachment #1: Type: Text/Plain, Size: 957 bytes --]

Joe Perches wrote:
> On Thu, 2010-06-03 at 01:33 +0200, Sven Eckelmann wrote:
> > Joe Perches wrote:
> > > On Thu, 2010-06-03 at 01:23 +0200, Sven Eckelmann wrote:
> > > > You've also changed the output. So you may partly broke batctl too
> > > > (have to check that first).
> > > 
> > > There was no change in output.
> > > MAC_FMT output is the same as %pM
> > 
> > I meant the other patch :)
> 
> batctl is parsing dmesg or equivalent?  ouch.

It has functionality to parse logfiles which for example could come from 
dmesg.

> If so, may I suggest you consider using something other than
> a message logging parser for batctl?
> 
> I glanced at the source and don't see any such use.
> It looks like it's only /sys, /proc and debugfs,
> but I only spent a few seconds at it.
> 
> http://www.open-mesh.net/changeset/1682/trunk?old_path=%2F&format=zip

see sys.c -> log_print
and read_file -> read_file

Best regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 23:56         ` Sven Eckelmann
@ 2010-06-03  0:20           ` Joe Perches
  2010-06-03  9:15             ` Marek Lindner
  0 siblings, 1 reply; 17+ messages in thread
From: Joe Perches @ 2010-06-03  0:20 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: devel, Greg Kroah-Hartman, b.a.t.m.a.n, b.a.t.m.a.n,
	linux-kernel, Simon Wunderlich, Marek Lindner

On Thu, 2010-06-03 at 01:56 +0200, Sven Eckelmann wrote:
> see sys.c -> log_print
> and read_file -> read_file

Yuck.

The patch changes the prefix from "batman-adv:" to "batman_adv: "
so yes, it would break as-is.

I think the concept is broken though, I believe dmesg output
specifically is not guaranteed to remain stable, and batman should
use some other, perhaps private, logger based on ethtool events.

cheers, Joe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-03  0:20           ` Joe Perches
@ 2010-06-03  9:15             ` Marek Lindner
  2010-06-03 14:45               ` Greg KH
  0 siblings, 1 reply; 17+ messages in thread
From: Marek Lindner @ 2010-06-03  9:15 UTC (permalink / raw)
  To: b.a.t.m.a.n, linux-kernel
  Cc: Joe Perches, devel, Greg Kroah-Hartman, Simon Wunderlich

On Thursday 03 June 2010 08:20:01 Joe Perches wrote:
> The patch changes the prefix from "batman-adv:" to "batman_adv: "
> so yes, it would break as-is.
> 
> I think the concept is broken though, I believe dmesg output
> specifically is not guaranteed to remain stable, and batman should
> use some other, perhaps private, logger based on ethtool events.

I think changing a dash to an underscore is not such a big deal (I did not 
check the rest of the patch yet). But I'm interested to hear more about your 
"private logger" idea because the current solution is far from being perfect. 
As we have to debug the routing protocol every now and then it would be very 
helpful to get direct access to some internal logging facility. In fact, that 
existed before (inside of /proc) but was removed to be more compliant with the 
linux kernel and the existing log facilities.

Regards,
Marek

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 20:10 [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM Joe Perches
  2010-06-02 23:23 ` Sven Eckelmann
@ 2010-06-03 13:58 ` Sven Eckelmann
  2010-06-03 14:39 ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
  2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
  3 siblings, 0 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-03 13:58 UTC (permalink / raw)
  To: b.a.t.m.a.n
  Cc: devel, b.a.t.m.a.n, Greg Kroah-Hartman, linux-kernel,
	Simon Wunderlich, Joe Perches, Marek Lindner

[-- Attachment #1: Type: Text/Plain, Size: 505 bytes --]

Joe Perches wrote:
> Remove the last uses of MAC_FMT
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  drivers/staging/batman-adv/main.c              |    3 +-
>  drivers/staging/batman-adv/translation-table.c |   25
> ++++------------------- 2 files changed, 6 insertions(+), 22 deletions(-)

Just noticed that this patch collides with another one which is waiting in 
GregKH's queue. I will try to rewrite it on top of that. I hope that this is 
ok for you.

Best regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [B.A.T.M.A.N.] [PATCH-trunk] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-02 20:10 [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM Joe Perches
  2010-06-02 23:23 ` Sven Eckelmann
  2010-06-03 13:58 ` Sven Eckelmann
@ 2010-06-03 14:39 ` Sven Eckelmann
  2010-06-03 14:44   ` [B.A.T.M.A.N.] [PATCH-maint] " Sven Eckelmann
  2010-06-03 14:51   ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
  2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
  3 siblings, 2 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-03 14:39 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
[sven.eckelmann@gmx.de: Adapted for current batman-adv version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 batman-adv-kernelland/bat_printk.c        |   50 +++++++++++++++++++++++++++++
 batman-adv-kernelland/compat.h            |   12 +++---
 batman-adv-kernelland/main.c              |    3 +-
 batman-adv-kernelland/translation-table.c |   24 ++-----------
 4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/batman-adv-kernelland/bat_printk.c b/batman-adv-kernelland/bat_printk.c
index 55c351a..4a02d7e 100644
--- a/batman-adv-kernelland/bat_printk.c
+++ b/batman-adv-kernelland/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/batman-adv-kernelland/compat.h b/batman-adv-kernelland/compat.h
index a211a36..614d116 100644
--- a/batman-adv-kernelland/compat.h
+++ b/batman-adv-kernelland/compat.h
@@ -74,12 +74,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) \
@@ -235,6 +229,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/batman-adv-kernelland/main.c b/batman-adv-kernelland/main.c
index c9132c0..20a0d54 100644
--- a/batman-adv-kernelland/main.c
+++ b/batman-adv-kernelland/main.c
@@ -227,8 +227,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/batman-adv-kernelland/translation-table.c b/batman-adv-kernelland/translation-table.c
index 009789e..8edc175 100644
--- a/batman-adv-kernelland/translation-table.c
+++ b/batman-adv-kernelland/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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [B.A.T.M.A.N.] [PATCH-maint] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-03 14:39 ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
@ 2010-06-03 14:44   ` Sven Eckelmann
  2010-06-03 14:51   ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
  1 sibling, 0 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-03 14:44 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
[sven.eckelmann@gmx.de: Adapted for current batman-adv version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-03  9:15             ` Marek Lindner
@ 2010-06-03 14:45               ` Greg KH
  0 siblings, 0 replies; 17+ messages in thread
From: Greg KH @ 2010-06-03 14:45 UTC (permalink / raw)
  To: Marek Lindner
  Cc: devel, b.a.t.m.a.n, linux-kernel, Simon Wunderlich, Joe Perches

On Thu, Jun 03, 2010 at 05:15:53PM +0800, Marek Lindner wrote:
> On Thursday 03 June 2010 08:20:01 Joe Perches wrote:
> > The patch changes the prefix from "batman-adv:" to "batman_adv: "
> > so yes, it would break as-is.
> > 
> > I think the concept is broken though, I believe dmesg output
> > specifically is not guaranteed to remain stable, and batman should
> > use some other, perhaps private, logger based on ethtool events.
> 
> I think changing a dash to an underscore is not such a big deal (I did not 
> check the rest of the patch yet). But I'm interested to hear more about your 
> "private logger" idea because the current solution is far from being perfect. 
> As we have to debug the routing protocol every now and then it would be very 
> helpful to get direct access to some internal logging facility. In fact, that 
> existed before (inside of /proc) but was removed to be more compliant with the 
> linux kernel and the existing log facilities.

You can always use debugfs if you like for something like this.

Or tie into the profile/perf subsystem, that might be even easier.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH-trunk] drivers/staging/batman-adv: Convert MAC_FMT to %pM
  2010-06-03 14:39 ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
  2010-06-03 14:44   ` [B.A.T.M.A.N.] [PATCH-maint] " Sven Eckelmann
@ 2010-06-03 14:51   ` Sven Eckelmann
  1 sibling, 0 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-03 14:51 UTC (permalink / raw)
  To: b.a.t.m.a.n, Marek Lindner

[-- Attachment #1: Type: Text/Plain, Size: 423 bytes --]

Sven Eckelmann wrote:
> From: Joe Perches <joe@perches.com>
> 
> Remove the last uses of MAC_FMT
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> [sven.eckelmann@gmx.de: Adapted for current batman-adv version]
> Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
> ---

Marek, can you please remove the "drivers/staging/" in the subject before 
amending both patches? Missed it :(

Best regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: Convert MAC_FMT to %pM
  2010-06-02 20:10 [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM Joe Perches
                   ` (2 preceding siblings ...)
  2010-06-03 14:39 ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
@ 2010-06-04 14:18 ` Sven Eckelmann
  2010-06-04 14:19   ` Sven Eckelmann
                     ` (2 more replies)
  3 siblings, 3 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-04 14:18 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
[sven.eckelmann@gmx.de: Adapted for current batman-adv version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 Marek, can you please test it with 2.6.21?
 It was rebased on top of "bonding and interface alternating"

 batman-adv-kernelland/bat_printk.c        |   50 +++++++++++++++++++++++++++++
 batman-adv-kernelland/compat.h            |   12 +++---
 batman-adv-kernelland/main.c              |    3 +-
 batman-adv-kernelland/translation-table.c |   24 ++-----------
 4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/batman-adv-kernelland/bat_printk.c b/batman-adv-kernelland/bat_printk.c
index 55c351a..4a02d7e 100644
--- a/batman-adv-kernelland/bat_printk.c
+++ b/batman-adv-kernelland/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/batman-adv-kernelland/compat.h b/batman-adv-kernelland/compat.h
index a211a36..614d116 100644
--- a/batman-adv-kernelland/compat.h
+++ b/batman-adv-kernelland/compat.h
@@ -74,12 +74,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) \
@@ -235,6 +229,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/batman-adv-kernelland/main.c b/batman-adv-kernelland/main.c
index c9132c0..20a0d54 100644
--- a/batman-adv-kernelland/main.c
+++ b/batman-adv-kernelland/main.c
@@ -227,8 +227,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/batman-adv-kernelland/translation-table.c b/batman-adv-kernelland/translation-table.c
index 009789e..8edc175 100644
--- a/batman-adv-kernelland/translation-table.c
+++ b/batman-adv-kernelland/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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: Convert MAC_FMT to %pM
  2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
@ 2010-06-04 14:19   ` Sven Eckelmann
  2010-06-04 14:24   ` [B.A.T.M.A.N.] [PATCHv2-maint] " Sven Eckelmann
  2010-06-05 17:44   ` [B.A.T.M.A.N.] [PATCHv2-trunk] " Simon Wunderlich
  2 siblings, 0 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-04 14:19 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
[sven.eckelmann@gmx.de: Adapted for current batman-adv version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 Marek, can you please test it with 2.6.21?
 It was rebased on top of "bonding and interface alternating"

 batman-adv-kernelland/bat_printk.c        |   50 +++++++++++++++++++++++++++++
 batman-adv-kernelland/compat.h            |   12 +++---
 batman-adv-kernelland/main.c              |    3 +-
 batman-adv-kernelland/translation-table.c |   24 ++-----------
 4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/batman-adv-kernelland/bat_printk.c b/batman-adv-kernelland/bat_printk.c
index 55c351a..4a02d7e 100644
--- a/batman-adv-kernelland/bat_printk.c
+++ b/batman-adv-kernelland/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/batman-adv-kernelland/compat.h b/batman-adv-kernelland/compat.h
index a211a36..614d116 100644
--- a/batman-adv-kernelland/compat.h
+++ b/batman-adv-kernelland/compat.h
@@ -74,12 +74,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) \
@@ -235,6 +229,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/batman-adv-kernelland/main.c b/batman-adv-kernelland/main.c
index c9132c0..20a0d54 100644
--- a/batman-adv-kernelland/main.c
+++ b/batman-adv-kernelland/main.c
@@ -227,8 +227,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/batman-adv-kernelland/translation-table.c b/batman-adv-kernelland/translation-table.c
index 009789e..8edc175 100644
--- a/batman-adv-kernelland/translation-table.c
+++ b/batman-adv-kernelland/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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2-maint] batman-adv: Convert MAC_FMT to %pM
  2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
  2010-06-04 14:19   ` Sven Eckelmann
@ 2010-06-04 14:24   ` Sven Eckelmann
  2010-06-05 17:44   ` [B.A.T.M.A.N.] [PATCHv2-trunk] " Simon Wunderlich
  2 siblings, 0 replies; 17+ messages in thread
From: Sven Eckelmann @ 2010-06-04 14:24 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Remove the last uses of MAC_FMT

Signed-off-by: Joe Perches <joe@perches.com>
[sven.eckelmann@gmx.de: Adapted for current batman-adv version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 Marek, can you please test it with 2.6.21?

 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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: Convert MAC_FMT to %pM
  2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
  2010-06-04 14:19   ` Sven Eckelmann
  2010-06-04 14:24   ` [B.A.T.M.A.N.] [PATCHv2-maint] " Sven Eckelmann
@ 2010-06-05 17:44   ` Simon Wunderlich
  2 siblings, 0 replies; 17+ messages in thread
From: Simon Wunderlich @ 2010-06-05 17:44 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

[-- Attachment #1: Type: text/plain, Size: 6058 bytes --]

Thank you, i've applied this patch in svn r1688. 

I've tested compiling against 2.6.21, 2.6.24, 2.6.27 - no problem.

best regards,
	Simon
On Fri, Jun 04, 2010 at 04:18:57PM +0200, Sven Eckelmann wrote:
> From: Joe Perches <joe@perches.com>
> 
> Remove the last uses of MAC_FMT
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> [sven.eckelmann@gmx.de: Adapted for current batman-adv version]
> Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
> ---
>  Marek, can you please test it with 2.6.21?
>  It was rebased on top of "bonding and interface alternating"
> 
>  batman-adv-kernelland/bat_printk.c        |   50 +++++++++++++++++++++++++++++
>  batman-adv-kernelland/compat.h            |   12 +++---
>  batman-adv-kernelland/main.c              |    3 +-
>  batman-adv-kernelland/translation-table.c |   24 ++-----------
>  4 files changed, 61 insertions(+), 28 deletions(-)
> 
> diff --git a/batman-adv-kernelland/bat_printk.c b/batman-adv-kernelland/bat_printk.c
> index 55c351a..4a02d7e 100644
> --- a/batman-adv-kernelland/bat_printk.c
> +++ b/batman-adv-kernelland/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/batman-adv-kernelland/compat.h b/batman-adv-kernelland/compat.h
> index a211a36..614d116 100644
> --- a/batman-adv-kernelland/compat.h
> +++ b/batman-adv-kernelland/compat.h
> @@ -74,12 +74,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) \
> @@ -235,6 +229,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/batman-adv-kernelland/main.c b/batman-adv-kernelland/main.c
> index c9132c0..20a0d54 100644
> --- a/batman-adv-kernelland/main.c
> +++ b/batman-adv-kernelland/main.c
> @@ -227,8 +227,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/batman-adv-kernelland/translation-table.c b/batman-adv-kernelland/translation-table.c
> index 009789e..8edc175 100644
> --- a/batman-adv-kernelland/translation-table.c
> +++ b/batman-adv-kernelland/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);
> -- 
> 1.7.1
> 
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-06-05 17:44 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-02 20:10 [B.A.T.M.A.N.] [PATCH] drivers/staging/batman-adv: Convert MAC_FMT to %pM Joe Perches
2010-06-02 23:23 ` Sven Eckelmann
2010-06-02 23:32   ` Joe Perches
2010-06-02 23:33     ` Sven Eckelmann
2010-06-02 23:47       ` Joe Perches
2010-06-02 23:56         ` Sven Eckelmann
2010-06-03  0:20           ` Joe Perches
2010-06-03  9:15             ` Marek Lindner
2010-06-03 14:45               ` Greg KH
2010-06-03 13:58 ` Sven Eckelmann
2010-06-03 14:39 ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
2010-06-03 14:44   ` [B.A.T.M.A.N.] [PATCH-maint] " Sven Eckelmann
2010-06-03 14:51   ` [B.A.T.M.A.N.] [PATCH-trunk] " Sven Eckelmann
2010-06-04 14:18 ` [B.A.T.M.A.N.] [PATCHv2-trunk] batman-adv: " Sven Eckelmann
2010-06-04 14:19   ` Sven Eckelmann
2010-06-04 14:24   ` [B.A.T.M.A.N.] [PATCHv2-maint] " Sven Eckelmann
2010-06-05 17:44   ` [B.A.T.M.A.N.] [PATCHv2-trunk] " Simon Wunderlich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).