netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs
@ 2010-12-04  2:33 Joe Perches
  2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Joe Perches @ 2010-12-04  2:33 UTC (permalink / raw)
  To: Marcel Holtmann, Gustavo F. Padovan,
	linux-bluetooth-u79uwXL29TY76Z2rM5mHXA
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Using vsprintf extensions can save text and data.
Add %pMbt for the byte reversed output for bluetooth addresses.

Joe Perches (2):
  vsprintf: Add %pMbt, bluetooth mac address
  bluetooth: Use printf extension %pMbt

 lib/vsprintf.c              |    6 +++++-
 net/bluetooth/bnep/core.c   |    3 +--
 net/bluetooth/cmtp/core.c   |    2 +-
 net/bluetooth/hci_conn.c    |    6 +++---
 net/bluetooth/hci_core.c    |    8 ++++----
 net/bluetooth/hci_event.c   |    6 +++---
 net/bluetooth/hci_sysfs.c   |   10 +++++-----
 net/bluetooth/hidp/core.c   |    4 ++--
 net/bluetooth/l2cap.c       |   19 +++++++++----------
 net/bluetooth/lib.c         |   14 --------------
 net/bluetooth/rfcomm/core.c |   16 ++++++++--------
 net/bluetooth/rfcomm/sock.c |    8 ++++----
 net/bluetooth/rfcomm/tty.c  |    6 +++---
 net/bluetooth/sco.c         |   12 ++++++------
 14 files changed, 54 insertions(+), 66 deletions(-)

-- 
1.7.3.2.245.g03276.dirty

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

* [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address
  2010-12-04  2:33 [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Joe Perches
@ 2010-12-04  2:33 ` Joe Perches
  2010-12-04 11:03   ` Michał Mirosław
  2010-12-06 18:11   ` Gustavo F. Padovan
  2010-12-04  2:33 ` [PATCH 2/2] bluetooth: Use printf extension %pMbt Joe Perches
  2012-05-09  9:01 ` [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Andrei Emeltchenko
  2 siblings, 2 replies; 11+ messages in thread
From: Joe Perches @ 2010-12-04  2:33 UTC (permalink / raw)
  To: Marcel Holtmann, Gustavo F. Padovan, linux-kernel; +Cc: netdev

Bluetooth output the MAC address in reverse order.
Bluetooth memory order: 00 01 02 03 04 05 is output "05:04:03:02:01:00".

This can save overall text when bluetooth is compiled in.

Bluetooth currently uses a very slightly unsafe local function (batostr)
to output these formatted addresses.

Adding %pMbt allows the batostr function to be removed.

For x86:

$ size lib/vsprintf*.o*
   text	   data	    bss	    dec	    hex	filename
   8189	      0	      2	   8191	   1fff	lib/vsprintf.o.defconfig.new
   8150	      0	      2	   8152	   1fd8	lib/vsprintf.o.defconfig.old
  18633	     56	   3936	  22625	   5861	lib/vsprintf.o.allyesconfig.new
  18571	     56	   3920	  22547	   5813	lib/vsprintf.o.allyesconfig.old

Signed-off-by: Joe Perches <joe@perches.com>
---
 lib/vsprintf.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3d..9346ed9 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -700,15 +700,18 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 	char *p = mac_addr;
 	int i;
 	char separator;
+	bool bluetooth = false;
 
 	if (fmt[1] == 'F') {		/* FDDI canonical format */
 		separator = '-';
 	} else {
 		separator = ':';
+		if (fmt[1] == 'b' && fmt[2] == 't')
+			bluetooth = true;
 	}
 
 	for (i = 0; i < 6; i++) {
-		p = pack_hex_byte(p, addr[i]);
+		p = pack_hex_byte(p, addr[!bluetooth ? i : 5 - i]);
 		if (fmt[0] == 'M' && i != 5)
 			*p++ = separator;
 	}
@@ -1012,6 +1015,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
 					/* [mM]F (FDDI, bit reversed) */
+					/* [mM]bt (Bluetooth, index:543210) */
 		return mac_address_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
 					 * 4:	1.2.3.4
-- 
1.7.3.2.245.g03276.dirty

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

* [PATCH 2/2] bluetooth: Use printf extension %pMbt
  2010-12-04  2:33 [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Joe Perches
  2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
@ 2010-12-04  2:33 ` Joe Perches
  2010-12-06 18:15   ` Gustavo F. Padovan
  2012-05-09  9:01 ` [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Andrei Emeltchenko
  2 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2010-12-04  2:33 UTC (permalink / raw)
  To: Marcel Holtmann, Gustavo F. Padovan
  Cc: netdev, David S. Miller, linux-bluetooth, linux-kernel

Save some text and bss.
Remove function batostr so there's no possibility of bad output.

from the net/bluetooth directory:

$ size built-in.o.*
   text	   data	    bss	    dec	    hex	filename
 293562	  16265	  70088	 379915	  5cc0b	built-in.o.allyesconfig.new
 294619	  16269	  70480	 381368	  5d1b8	built-in.o.allyesconfig.old
  30359	    772	     56	  31187	   79d3	built-in.o.btonly.new
  30555	    776	     92	  31423	   7abf	built-in.o.btonly.old

Signed-off-by: Joe Perches <joe@perches.com>
---
 net/bluetooth/bnep/core.c   |    3 +--
 net/bluetooth/cmtp/core.c   |    2 +-
 net/bluetooth/hci_conn.c    |    6 +++---
 net/bluetooth/hci_core.c    |    8 ++++----
 net/bluetooth/hci_event.c   |    6 +++---
 net/bluetooth/hci_sysfs.c   |   10 +++++-----
 net/bluetooth/hidp/core.c   |    4 ++--
 net/bluetooth/l2cap.c       |   19 +++++++++----------
 net/bluetooth/lib.c         |   14 --------------
 net/bluetooth/rfcomm/core.c |   16 ++++++++--------
 net/bluetooth/rfcomm/sock.c |    8 ++++----
 net/bluetooth/rfcomm/tty.c  |    6 +++---
 net/bluetooth/sco.c         |   12 ++++++------
 13 files changed, 49 insertions(+), 65 deletions(-)

diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 5868597..3d4530f 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -199,8 +199,7 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len)
 			memcpy(a1, data, ETH_ALEN); data += ETH_ALEN;
 			a2 = data; data += ETH_ALEN;
 
-			BT_DBG("mc filter %s -> %s",
-				batostr((void *) a1), batostr((void *) a2));
+			BT_DBG("mc filter %pMbt -> %pMbt", a1, a2);
 
 			#define INCA(a) { int i = 5; while (i >=0 && ++a[i--] == 0); }
 
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 8e5f292..f72bca7 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -344,7 +344,7 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
 
 	BT_DBG("mtu %d", session->mtu);
 
-	sprintf(session->name, "%s", batostr(&bt_sk(sock->sk)->dst));
+	sprintf(session->name, "%pMbt", &bt_sk(sock->sk)->dst);
 
 	session->sock  = sock;
 	session->state = BT_CONFIG;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 0b1e460..d9e3eb3 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -221,7 +221,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 {
 	struct hci_conn *conn;
 
-	BT_DBG("%s dst %s", hdev->name, batostr(dst));
+	BT_DBG("%s dst %pMbt", hdev->name, dst);
 
 	conn = kzalloc(sizeof(struct hci_conn), GFP_ATOMIC);
 	if (!conn)
@@ -325,7 +325,7 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
 	struct hci_dev *hdev = NULL;
 	struct list_head *p;
 
-	BT_DBG("%s -> %s", batostr(src), batostr(dst));
+	BT_DBG("%pMbt -> %pMbt", src, dst);
 
 	read_lock_bh(&hci_dev_list_lock);
 
@@ -366,7 +366,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 	struct hci_conn *acl;
 	struct hci_conn *sco;
 
-	BT_DBG("%s dst %s", hdev->name, batostr(dst));
+	BT_DBG("%s dst %pMbt", hdev->name, dst);
 
 	if (!(acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst))) {
 		if (!(acl = hci_conn_add(hdev, ACL_LINK, dst)))
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bc2a052..47962af 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -338,7 +338,7 @@ struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *b
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
 
-	BT_DBG("cache %p, %s", cache, batostr(bdaddr));
+	BT_DBG("cache %p, %pMbt", cache, bdaddr);
 
 	for (e = cache->list; e; e = e->next)
 		if (!bacmp(&e->data.bdaddr, bdaddr))
@@ -351,7 +351,7 @@ void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data)
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
 
-	BT_DBG("cache %p, %s", cache, batostr(&data->bdaddr));
+	BT_DBG("cache %p, %pMbt", cache, &data->bdaddr);
 
 	if (!(e = hci_inquiry_cache_lookup(hdev, &data->bdaddr))) {
 		/* Entry not in the cache. Add new one. */
@@ -1478,8 +1478,8 @@ static inline void hci_acl_tx_to(struct hci_dev *hdev)
 	list_for_each(p, &h->list) {
 		c = list_entry(p, struct hci_conn, list);
 		if (c->type == ACL_LINK && c->sent) {
-			BT_ERR("%s killing stalled ACL connection %s",
-				hdev->name, batostr(&c->dst));
+			BT_ERR("%s killing stalled ACL connection %pMbt",
+			       hdev->name, &c->dst);
 			hci_acl_disconn(c, 0x13);
 		}
 	}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3c1957c..53f833f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -566,7 +566,7 @@ static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
 
 	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
 
-	BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn);
+	BT_DBG("%s bdaddr %pMbt conn %p", hdev->name, &cp->bdaddr, conn);
 
 	if (status) {
 		if (conn && conn->state == BT_CONNECT) {
@@ -984,8 +984,8 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
 	struct hci_ev_conn_request *ev = (void *) skb->data;
 	int mask = hdev->link_mode;
 
-	BT_DBG("%s bdaddr %s type 0x%x", hdev->name,
-					batostr(&ev->bdaddr), ev->link_type);
+	BT_DBG("%s bdaddr %pMbt type 0x%x",
+	       hdev->name, &ev->bdaddr, ev->link_type);
 
 	mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
 
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 5fce3d6..5dac407 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -37,7 +37,7 @@ static ssize_t show_link_type(struct device *dev, struct device_attribute *attr,
 static ssize_t show_link_address(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct hci_conn *conn = dev_get_drvdata(dev);
-	return sprintf(buf, "%s\n", batostr(&conn->dst));
+	return sprintf(buf, "%pMbt\n", &conn->dst);
 }
 
 static ssize_t show_link_features(struct device *dev, struct device_attribute *attr, char *buf)
@@ -236,7 +236,7 @@ static ssize_t show_class(struct device *dev, struct device_attribute *attr, cha
 static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct hci_dev *hdev = dev_get_drvdata(dev);
-	return sprintf(buf, "%s\n", batostr(&hdev->bdaddr));
+	return sprintf(buf, "%pMbt\n", &hdev->bdaddr);
 }
 
 static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
@@ -404,8 +404,8 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
 
 	for (e = cache->list; e; e = e->next) {
 		struct inquiry_data *data = &e->data;
-		seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
-			   batostr(&data->bdaddr),
+		seq_printf(f, "%pMbt %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
+			   &data->bdaddr,
 			   data->pscan_rep_mode, data->pscan_period_mode,
 			   data->pscan_mode, data->dev_class[2],
 			   data->dev_class[1], data->dev_class[0],
@@ -442,7 +442,7 @@ static int blacklist_show(struct seq_file *f, void *p)
 
 		b = list_entry(l, struct bdaddr_list, list);
 
-		seq_printf(f, "%s\n", batostr(&b->bdaddr));
+		seq_printf(f, "%pMbt\n", &b->bdaddr);
 	}
 
 	hci_dev_unlock_bh(hdev);
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 29544c2..cde8827 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -787,8 +787,8 @@ static int hidp_setup_hid(struct hidp_session *session,
 	hid->country = req->country;
 
 	strncpy(hid->name, req->name, 128);
-	strncpy(hid->phys, batostr(&bt_sk(session->ctrl_sock->sk)->src), 64);
-	strncpy(hid->uniq, batostr(&bt_sk(session->ctrl_sock->sk)->dst), 64);
+	snprintf(hid->phys, 64, "%pMbt", &bt_sk(session->ctrl_sock->sk)->src);
+	snprintf(hid->uniq, 64, "%pMbt", &bt_sk(session->ctrl_sock->sk)->dst);
 
 	hid->dev.parent = hidp_get_device(session);
 	hid->ll_driver = &hidp_hid_driver;
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 12b4aa2..72b8306 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1057,8 +1057,7 @@ static int l2cap_do_connect(struct sock *sk)
 	__u8 auth_type;
 	int err;
 
-	BT_DBG("%s -> %s psm 0x%2.2x", batostr(src), batostr(dst),
-							l2cap_pi(sk)->psm);
+	BT_DBG("%pMbt -> %pMbt psm 0x%2.2x", src, dst, l2cap_pi(sk)->psm);
 
 	hdev = hci_get_route(dst, src);
 	if (!hdev)
@@ -4525,7 +4524,7 @@ static int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 	if (type != ACL_LINK)
 		return -EINVAL;
 
-	BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr));
+	BT_DBG("hdev %s, bdaddr %pMbt", hdev->name, bdaddr);
 
 	/* Find listening sockets and check their link_mode */
 	read_lock(&l2cap_sk_list.lock);
@@ -4553,7 +4552,7 @@ static int l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
 {
 	struct l2cap_conn *conn;
 
-	BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
+	BT_DBG("hcon %p bdaddr %pMbt status %d", hcon, &hcon->dst, status);
 
 	if (hcon->type != ACL_LINK)
 		return -EINVAL;
@@ -4798,12 +4797,12 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
 	sk_for_each(sk, node, &l2cap_sk_list.head) {
 		struct l2cap_pinfo *pi = l2cap_pi(sk);
 
-		seq_printf(f, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n",
-					batostr(&bt_sk(sk)->src),
-					batostr(&bt_sk(sk)->dst),
-					sk->sk_state, __le16_to_cpu(pi->psm),
-					pi->scid, pi->dcid,
-					pi->imtu, pi->omtu, pi->sec_level);
+		seq_printf(f, "%pMbt %pMbt %d %d 0x%4.4x 0x%4.4x %d %d %d\n",
+			   &bt_sk(sk)->src,
+			   &bt_sk(sk)->dst,
+			   sk->sk_state, __le16_to_cpu(pi->psm),
+			   pi->scid, pi->dcid,
+			   pi->imtu, pi->omtu, pi->sec_level);
 	}
 
 	read_unlock_bh(&l2cap_sk_list.lock);
diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c
index b826d1b..bfc8bbb 100644
--- a/net/bluetooth/lib.c
+++ b/net/bluetooth/lib.c
@@ -44,20 +44,6 @@ void baswap(bdaddr_t *dst, bdaddr_t *src)
 }
 EXPORT_SYMBOL(baswap);
 
-char *batostr(bdaddr_t *ba)
-{
-	static char str[2][18];
-	static int i = 1;
-
-	i ^= 1;
-	sprintf(str[i], "%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 str[i];
-}
-EXPORT_SYMBOL(batostr);
-
 /* Bluetooth error codes to Unix errno mapping */
 int bt_err(__u16 code)
 {
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index fa642aa..532e5ad 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -393,8 +393,8 @@ static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
 	int err = 0;
 	u8 dlci;
 
-	BT_DBG("dlc %p state %ld %s %s channel %d",
-			d, d->state, batostr(src), batostr(dst), channel);
+	BT_DBG("dlc %p state %ld %pMbt %pMbt channel %d",
+	       d, d->state, src, dst, channel);
 
 	if (channel < 1 || channel > 30)
 		return -EINVAL;
@@ -692,7 +692,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
 	struct socket *sock;
 	struct sock *sk;
 
-	BT_DBG("%s %s", batostr(src), batostr(dst));
+	BT_DBG("%pMbt %pMbt", src, dst);
 
 	*err = rfcomm_l2sock_create(&sock);
 	if (*err < 0)
@@ -2120,11 +2120,11 @@ static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x)
 			struct sock *sk = s->sock->sk;
 			struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list);
 
-			seq_printf(f, "%s %s %ld %d %d %d %d\n",
-						batostr(&bt_sk(sk)->src),
-						batostr(&bt_sk(sk)->dst),
-						d->state, d->dlci, d->mtu,
-						d->rx_credits, d->tx_credits);
+			seq_printf(f, "%pMbt %pMbt %ld %d %d %d %d\n",
+				   &bt_sk(sk)->src,
+				   &bt_sk(sk)->dst,
+				   d->state, d->dlci, d->mtu,
+				   d->rx_credits, d->tx_credits);
 		}
 	}
 
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 0207bd6..bbbc7479 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -350,7 +350,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
 	struct sock *sk = sock->sk;
 	int err = 0;
 
-	BT_DBG("sk %p %s", sk, batostr(&sa->rc_bdaddr));
+	BT_DBG("sk %p %pMbt", sk, &sa->rc_bdaddr);
 
 	if (!addr || addr->sa_family != AF_BLUETOOTH)
 		return -EINVAL;
@@ -979,9 +979,9 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
 	read_lock_bh(&rfcomm_sk_list.lock);
 
 	sk_for_each(sk, node, &rfcomm_sk_list.head) {
-		seq_printf(f, "%s %s %d %d\n",
-				batostr(&bt_sk(sk)->src),
-				batostr(&bt_sk(sk)->dst),
+		seq_printf(f, "%pMbt %pMbt %d %d\n",
+				&bt_sk(sk)->src,
+				&bt_sk(sk)->dst,
 				sk->sk_state, rfcomm_pi(sk)->channel);
 	}
 
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index a9b81f5..740c99b 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -183,7 +183,7 @@ static struct device *rfcomm_get_device(struct rfcomm_dev *dev)
 static ssize_t show_address(struct device *tty_dev, struct device_attribute *attr, char *buf)
 {
 	struct rfcomm_dev *dev = dev_get_drvdata(tty_dev);
-	return sprintf(buf, "%s\n", batostr(&dev->dst));
+	return sprintf(buf, "%pMbt\n", &dev->dst);
 }
 
 static ssize_t show_channel(struct device *tty_dev, struct device_attribute *attr, char *buf)
@@ -685,8 +685,8 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
 	if (!dev)
 		return -ENODEV;
 
-	BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
-				dev->channel, atomic_read(&dev->opened));
+	BT_DBG("dev %p dst %pMbt channel %d opened %d",
+	       dev, &dev->dst, dev->channel, atomic_read(&dev->opened));
 
 	if (atomic_inc_return(&dev->opened) > 1)
 		return 0;
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 66b9e5c..ac8370e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -183,7 +183,7 @@ static int sco_connect(struct sock *sk)
 	struct hci_dev  *hdev;
 	int err, type;
 
-	BT_DBG("%s -> %s", batostr(src), batostr(dst));
+	BT_DBG("%pMbt -> %pMbt", src, dst);
 
 	if (!(hdev = hci_get_route(dst, src)))
 		return -EHOSTUNREACH;
@@ -457,7 +457,7 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
 	bdaddr_t *src = &sa->sco_bdaddr;
 	int err = 0;
 
-	BT_DBG("sk %p %s", sk, batostr(&sa->sco_bdaddr));
+	BT_DBG("sk %p %pMbt", sk, src);
 
 	if (!addr || addr->sa_family != AF_BLUETOOTH)
 		return -EINVAL;
@@ -884,7 +884,7 @@ static int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
 	if (type != SCO_LINK && type != ESCO_LINK)
 		return -EINVAL;
 
-	BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr));
+	BT_DBG("hdev %s, bdaddr %pMbt", hdev->name, bdaddr);
 
 	/* Find listening sockets */
 	read_lock(&sco_sk_list.lock);
@@ -905,7 +905,7 @@ static int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
 
 static int sco_connect_cfm(struct hci_conn *hcon, __u8 status)
 {
-	BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
+	BT_DBG("hcon %p bdaddr %pMbt status %d", hcon, &hcon->dst, status);
 
 	if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
 		return -EINVAL;
@@ -961,8 +961,8 @@ static int sco_debugfs_show(struct seq_file *f, void *p)
 	read_lock_bh(&sco_sk_list.lock);
 
 	sk_for_each(sk, node, &sco_sk_list.head) {
-		seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
-				batostr(&bt_sk(sk)->dst), sk->sk_state);
+		seq_printf(f, "%pMbt %pMbt %d\n",
+			   &bt_sk(sk)->src, &bt_sk(sk)->dst, sk->sk_state);
 	}
 
 	read_unlock_bh(&sco_sk_list.lock);
-- 
1.7.3.2.245.g03276.dirty

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

* Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address
  2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
@ 2010-12-04 11:03   ` Michał Mirosław
  2010-12-04 17:48     ` Joe Perches
  2010-12-06 18:11   ` Gustavo F. Padovan
  1 sibling, 1 reply; 11+ messages in thread
From: Michał Mirosław @ 2010-12-04 11:03 UTC (permalink / raw)
  To: Joe Perches; +Cc: Marcel Holtmann, Gustavo F. Padovan, linux-kernel, netdev

2010/12/4 Joe Perches <joe@perches.com>:
> Bluetooth output the MAC address in reverse order.
> Bluetooth memory order: 00 01 02 03 04 05 is output "05:04:03:02:01:00".
>
> This can save overall text when bluetooth is compiled in.
>
> Bluetooth currently uses a very slightly unsafe local function (batostr)
> to output these formatted addresses.
>
> Adding %pMbt allows the batostr function to be removed.

Just a nitpick:
You could call it %pMR, as in 'Reverse', so it sounds better when/if
some other subsystem uses it. It would also be a hint of what is this
doing instead of where it came from.

Best Regards,
Michał Mirosław

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

* Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address
  2010-12-04 11:03   ` Michał Mirosław
@ 2010-12-04 17:48     ` Joe Perches
  0 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2010-12-04 17:48 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Marcel Holtmann, Gustavo F. Padovan, linux-kernel, netdev

On Sat, 2010-12-04 at 12:03 +0100, Michał Mirosław wrote:
> 2010/12/4 Joe Perches <joe@perches.com>:
> > Bluetooth output the MAC address in reverse order.
> > Adding %pMbt allows the batostr function to be removed.
> Just a nitpick:
> You could call it %pMR, as in 'Reverse', so it sounds better when/if
> some other subsystem uses it. It would also be a hint of what is this
> doing instead of where it came from.

I considered that but believe %pMbt is clearer as most
likely no other subsystem will be quite so far (out to
lunch? in left field?  north? :) enough to do that again.

If any maintainer wants it changed, it's not any sort
of problem to me, say so and I'll resubmit it.

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

* Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address
  2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
  2010-12-04 11:03   ` Michał Mirosław
@ 2010-12-06 18:11   ` Gustavo F. Padovan
  1 sibling, 0 replies; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-12-06 18:11 UTC (permalink / raw)
  To: Joe Perches; +Cc: Marcel Holtmann, linux-kernel, netdev

Hi Joe,

* Joe Perches <joe@perches.com> [2010-12-03 18:33:03 -0800]:

> Bluetooth output the MAC address in reverse order.
> Bluetooth memory order: 00 01 02 03 04 05 is output "05:04:03:02:01:00".
> 
> This can save overall text when bluetooth is compiled in.
> 
> Bluetooth currently uses a very slightly unsafe local function (batostr)
> to output these formatted addresses.
> 
> Adding %pMbt allows the batostr function to be removed.
> 
> For x86:
> 
> $ size lib/vsprintf*.o*
>    text	   data	    bss	    dec	    hex	filename
>    8189	      0	      2	   8191	   1fff	lib/vsprintf.o.defconfig.new
>    8150	      0	      2	   8152	   1fd8	lib/vsprintf.o.defconfig.old
>   18633	     56	   3936	  22625	   5861	lib/vsprintf.o.allyesconfig.new
>   18571	     56	   3920	  22547	   5813	lib/vsprintf.o.allyesconfig.old
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Looks good to me.

Acked-by: Gustavo F. Padovan <padovan@profusion.mobi>

-- 
Gustavo F. Padovan
http://profusion.mobi

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

* Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt
  2010-12-04  2:33 ` [PATCH 2/2] bluetooth: Use printf extension %pMbt Joe Perches
@ 2010-12-06 18:15   ` Gustavo F. Padovan
  2010-12-06 18:50     ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-12-06 18:15 UTC (permalink / raw)
  To: Joe Perches
  Cc: Marcel Holtmann, netdev, David S. Miller, linux-bluetooth,
	linux-kernel

Hi Joe,

* Joe Perches <joe@perches.com> [2010-12-03 18:33:04 -0800]:

> Save some text and bss.
> Remove function batostr so there's no possibility of bad output.
> 
> from the net/bluetooth directory:
> 
> $ size built-in.o.*
>    text	   data	    bss	    dec	    hex	filename
>  293562	  16265	  70088	 379915	  5cc0b	built-in.o.allyesconfig.new
>  294619	  16269	  70480	 381368	  5d1b8	built-in.o.allyesconfig.old
>   30359	    772	     56	  31187	   79d3	built-in.o.btonly.new
>   30555	    776	     92	  31423	   7abf	built-in.o.btonly.old
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  net/bluetooth/bnep/core.c   |    3 +--
>  net/bluetooth/cmtp/core.c   |    2 +-
>  net/bluetooth/hci_conn.c    |    6 +++---
>  net/bluetooth/hci_core.c    |    8 ++++----
>  net/bluetooth/hci_event.c   |    6 +++---
>  net/bluetooth/hci_sysfs.c   |   10 +++++-----
>  net/bluetooth/hidp/core.c   |    4 ++--
>  net/bluetooth/l2cap.c       |   19 +++++++++----------
>  net/bluetooth/lib.c         |   14 --------------
>  net/bluetooth/rfcomm/core.c |   16 ++++++++--------
>  net/bluetooth/rfcomm/sock.c |    8 ++++----
>  net/bluetooth/rfcomm/tty.c  |    6 +++---
>  net/bluetooth/sco.c         |   12 ++++++------
>  13 files changed, 49 insertions(+), 65 deletions(-)

This patch doesn't apply to the bluetooth-next-2.6 tree. Can you please rebase
it against the bluetooth-next-2.6 tree? The tree is at:

git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth-next-2.6.git


-- 
Gustavo F. Padovan
http://profusion.mobi

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

* Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt
  2010-12-06 18:15   ` Gustavo F. Padovan
@ 2010-12-06 18:50     ` Joe Perches
  2010-12-06 20:07       ` Gustavo F. Padovan
  0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2010-12-06 18:50 UTC (permalink / raw)
  To: Gustavo F. Padovan, Michał Mirosław
  Cc: Marcel Holtmann, netdev, David S. Miller, linux-bluetooth,
	linux-kernel

On Mon, 2010-12-06 at 16:15 -0200, Gustavo F. Padovan wrote:
> This patch doesn't apply to the bluetooth-next-2.6 tree.
> Can you please rebase it against the bluetooth-next-2.6 tree?

No worries, it was done against next-20101202.

Do you care about using %pMR vs %pMbt as Michał suggested in
https://lkml.org/lkml/2010/12/4/21 ?

I think %pMbt more specific, Michał %pMR more generic.
Doesn't matter much to me.  Do tell, I'll resubmit either way.

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

* Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt
  2010-12-06 18:50     ` Joe Perches
@ 2010-12-06 20:07       ` Gustavo F. Padovan
  0 siblings, 0 replies; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-12-06 20:07 UTC (permalink / raw)
  To: Joe Perches
  Cc: Michał Mirosław, Marcel Holtmann, netdev,
	David S. Miller, linux-bluetooth, linux-kernel

Hi Joe,

* Joe Perches <joe@perches.com> [2010-12-06 10:50:13 -0800]:

> On Mon, 2010-12-06 at 16:15 -0200, Gustavo F. Padovan wrote:
> > This patch doesn't apply to the bluetooth-next-2.6 tree.
> > Can you please rebase it against the bluetooth-next-2.6 tree?
> 
> No worries, it was done against next-20101202.
> 
> Do you care about using %pMR vs %pMbt as Michał suggested in
> https://lkml.org/lkml/2010/12/4/21 ?

I'm fine either way. It depends more if another subsystem will want to use
%pMR or not as you said.

-- 
Gustavo F. Padovan
http://profusion.mobi

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

* Re: [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs
  2010-12-04  2:33 [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Joe Perches
  2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
  2010-12-04  2:33 ` [PATCH 2/2] bluetooth: Use printf extension %pMbt Joe Perches
@ 2012-05-09  9:01 ` Andrei Emeltchenko
  2012-05-11 23:21   ` Joe Perches
  2 siblings, 1 reply; 11+ messages in thread
From: Andrei Emeltchenko @ 2012-05-09  9:01 UTC (permalink / raw)
  To: Joe Perches
  Cc: Marcel Holtmann, Gustavo F. Padovan, linux-bluetooth, netdev,
	linux-kernel

Hi Joe

On Fri, Dec 03, 2010 at 06:33:02PM -0800, Joe Perches wrote:
> Using vsprintf extensions can save text and data.
> Add %pMbt for the byte reversed output for bluetooth addresses.
> 
> Joe Perches (2):
>   vsprintf: Add %pMbt, bluetooth mac address
>   bluetooth: Use printf extension %pMbt

I think this would be the best way to solve our issues with batostr.

BTW: What is the status with this patch series? I saw that it was acked by
Gustavo but not applied for some reason.

Best regards 
Andrei Emeltchenko 

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

* Re: [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs
  2012-05-09  9:01 ` [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Andrei Emeltchenko
@ 2012-05-11 23:21   ` Joe Perches
  0 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2012-05-11 23:21 UTC (permalink / raw)
  To: Andrei Emeltchenko
  Cc: Marcel Holtmann, Gustavo F. Padovan, linux-bluetooth, netdev,
	linux-kernel

On Wed, 2012-05-09 at 12:01 +0300, Andrei Emeltchenko wrote:
> Hi Joe
> 
> On Fri, Dec 03, 2010 at 06:33:02PM -0800, Joe Perches wrote:
> > Using vsprintf extensions can save text and data.
> > Add %pMbt for the byte reversed output for bluetooth addresses.
> > 
> > Joe Perches (2):
> >   vsprintf: Add %pMbt, bluetooth mac address
> >   bluetooth: Use printf extension %pMbt
> 
> I think this would be the best way to solve our issues with batostr.
> 
> BTW: What is the status with this patch series?

18 month old patches generally don't apply.

If you want to bring it forward or redo it,
please do.

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

end of thread, other threads:[~2012-05-11 23:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-04  2:33 [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Joe Perches
2010-12-04  2:33 ` [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Joe Perches
2010-12-04 11:03   ` Michał Mirosław
2010-12-04 17:48     ` Joe Perches
2010-12-06 18:11   ` Gustavo F. Padovan
2010-12-04  2:33 ` [PATCH 2/2] bluetooth: Use printf extension %pMbt Joe Perches
2010-12-06 18:15   ` Gustavo F. Padovan
2010-12-06 18:50     ` Joe Perches
2010-12-06 20:07       ` Gustavo F. Padovan
2012-05-09  9:01 ` [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Andrei Emeltchenko
2012-05-11 23:21   ` Joe Perches

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