linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, gustavo@padovan.org,
	David Herrmann <dh.herrmann@googlemail.com>
Subject: [PATCH 1/3] Bluetooth: Introduce ba2str()
Date: Tue,  8 May 2012 15:28:24 +0200	[thread overview]
Message-ID: <1336483706-1533-1-git-send-email-dh.herrmann@googlemail.com> (raw)

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

             reply	other threads:[~2012-05-08 13:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 13:28 David Herrmann [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336483706-1533-1-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=gustavo@padovan.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).