linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Bluetooth: Introduce ba2str()
@ 2012-05-08 13:28 David Herrmann
  2012-05-08 13:28 ` [PATCH 2/3] Bluetooth: Replace unsafe batostr() calls with ba2str() David Herrmann
  2012-05-08 13:28 ` [PATCH 3/3] Bluetooth: Remove batostr() David Herrmann
  0 siblings, 2 replies; 12+ messages in thread
From: David Herrmann @ 2012-05-08 13:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, gustavo, David Herrmann

We use batostr() in many debug messages even though it uses static
buffers. This is definitely not thread-safe and should be replaced by
buffers on the stack of the caller.
ba2str() is similar to batostr() but takes as argument a pointer to a
buffer of at least size BDADDR_STRLEN=18. It returns it's argument so we
can still use it in debug messages directly.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 include/net/bluetooth/bluetooth.h |    4 ++++
 net/bluetooth/lib.c               |   10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 2fb268f..9b22536 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -184,6 +184,10 @@ static inline void bacpy(bdaddr_t *dst, bdaddr_t *src)
 void baswap(bdaddr_t *dst, bdaddr_t *src);
 char *batostr(bdaddr_t *ba);
 
+#define BDADDR_STRLEN 18
+
+char *ba2str(bdaddr_t *ba, char buf[BDADDR_STRLEN]);
+
 /* Common socket structures and functions */
 
 #define bt_sk(__sk) ((struct bt_sock *) __sk)
diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c
index 84ff96f..6dcb788 100644
--- a/net/bluetooth/lib.c
+++ b/net/bluetooth/lib.c
@@ -62,6 +62,16 @@ char *batostr(bdaddr_t *ba)
 }
 EXPORT_SYMBOL(batostr);
 
+char *ba2str(bdaddr_t *ba, char buf[BDADDR_STRLEN])
+{
+	sprintf(buf, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+		ba->b[5], ba->b[4], ba->b[3],
+		ba->b[2], ba->b[1], ba->b[0]);
+
+	return buf;
+}
+EXPORT_SYMBOL(ba2str);
+
 /* Bluetooth error codes to Unix errno mapping */
 int bt_to_errno(__u16 code)
 {
-- 
1.7.10.1

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

end of thread, other threads:[~2012-05-09 13:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-08 13:28 [PATCH 1/3] Bluetooth: Introduce ba2str() David Herrmann
2012-05-08 13:28 ` [PATCH 2/3] Bluetooth: Replace unsafe batostr() calls with ba2str() David Herrmann
2012-05-08 13:49   ` Andrei Emeltchenko
2012-05-08 14:02     ` David Herrmann
2012-05-08 14:34       ` Andrei Emeltchenko
2012-05-08 13:28 ` [PATCH 3/3] Bluetooth: Remove batostr() David Herrmann
2012-05-08 14:30   ` Ulisses Furquim
2012-05-08 14:54     ` Marcel Holtmann
2012-05-08 18:11       ` Ulisses Furquim
2012-05-09  9:02         ` Andrei Emeltchenko
2012-05-09 11:17           ` Ulisses Furquim
2012-05-09 13:10             ` Gustavo Padovan

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).