Skip to contentSkip to conversation

Add and use vsprintf extension %pMbt for bluetooth macs

PATCH In review Joe Perches 7 participants 22 messages Dec 4, 2010 – Jun 21, 2012

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Add and use vsprintf extension %pMbt for bluetooth macs

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(-)
Signature · 1 line
1.7.3.2.245.g03276.dirty
#1 lore raw

PATCH 1/2 vsprintf: Add %pMbt, bluetooth mac address

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
---
 lib/vsprintf.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
lib/vsprintf.c +5 -1
index c150d3d..9346ed9 100644
@@ -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
Signature · 1 line
1.7.3.2.245.g03276.dirty
#5 lore raw

PATCH 2/2 bluetooth: Use printf extension %pMbt

In reply to Joe Perches

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
---
 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(-)
net/bluetooth/bnep/core.c +1 -2
index 5868597..3d4530f 100644
@@ -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); }
 
net/bluetooth/cmtp/core.c +1 -1
index 8e5f292..f72bca7 100644
@@ -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;
net/bluetooth/hci_conn.c +3 -3
index 0b1e460..d9e3eb3 100644
@@ -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)))
net/bluetooth/hci_core.c +4 -4
index bc2a052..47962af 100644
@@ -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);
 		}
 	}
net/bluetooth/hci_event.c +3 -3
index 3c1957c..53f833f 100644
@@ -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);
 
net/bluetooth/hci_sysfs.c +5 -5
index 5fce3d6..5dac407 100644
@@ -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);
net/bluetooth/hidp/core.c +2 -2
index 29544c2..cde8827 100644
@@ -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;
net/bluetooth/l2cap.c +9 -10
index 12b4aa2..72b8306 100644
@@ -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);
net/bluetooth/lib.c +0 -14
index b826d1b..bfc8bbb 100644
@@ -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)
 {
net/bluetooth/rfcomm/core.c +8 -8
index fa642aa..532e5ad 100644
@@ -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);
 		}
 	}
 
net/bluetooth/rfcomm/sock.c +4 -4
index 0207bd6..bbbc7479 100644
@@ -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);
 	}
 
net/bluetooth/rfcomm/tty.c +3 -3
index a9b81f5..740c99b 100644
@@ -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;
net/bluetooth/sco.c +6 -6
index 66b9e5c..ac8370e 100644
@@ -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);
Signature · 1 line
1.7.3.2.245.g03276.dirty
#2 lore raw

Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address

In reply to Joe Perches

2010/12/4 Joe Perches <[email protected]>:

Quoted 9 lines

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

#3 lore raw

Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address

Quoted 7 lines · Michał Mirosław

2010/12/4 Joe Perches <[email protected]>:

Quoted 2 lines

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.

Acked-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address

In reply to Joe Perches

Hi Joe,

Quoted 12 lines · Joe Perches

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:

Quoted 8 lines
$ 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

Looks good to me.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#6 lore raw

Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt

In reply to Joe Perches

Hi Joe,

Quoted 13 lines · Joe Perches

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
Quoted 15 lines
---
 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

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#7 lore raw

Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt

Quoted 2 lines · Gustavo F. Padovan

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.

#8 lore raw

Re: [PATCH 2/2] bluetooth: Use printf extension %pMbt

Hi Joe,

Quoted 8 lines · Joe Perches
Quoted 2 lines · Gustavo F. Padovan

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.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#9 lore raw
In reply to Joe Perches

Hi Joe

Quoted 6 lines · Joe Perches

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

#10 lore raw
Quoted 6 lines · Andrei Emeltchenko

Hi Joe

Quoted 3 lines · Joe Perches

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

Quoted 7 lines
Quoted 3 lines

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.

#11 lore raw

RFC 1/1 vsprintf: Add %pMR for Bluetooth MAC address

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
 lib/vsprintf.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
lib/vsprintf.c +17 -5
index abbabec..b767c3c 100644
@@ -557,17 +557,27 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 {
 	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
 	char *p = mac_addr;
-	int i;
+	int i, index;
 	char separator;
+	bool bluetooth = false;
 
-	if (fmt[1] == 'F') {		/* FDDI canonical format */
+	switch (fmt[1]) {
+	case 'F':
 		separator = '-';
-	} else {
+		break;
+
+	case 'R':
+		bluetooth = true;
+		/* fall through */
+
+	default:
 		separator = ':';
+		break;
 	}
 
 	for (i = 0; i < 6; i++) {
-		p = hex_byte_pack(p, addr[i]);
+		index = !bluetooth ? i : 5 - i;
+		p = hex_byte_pack(p, addr[index]);
 		if (fmt[0] == 'M' && i != 5)
 			*p++ = separator;
 	}
@@ -830,6 +840,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC Bluetooth address, bits reversed
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +901,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return resource_string(buf, end, ptr, spec, fmt);
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
-					/* [mM]F (FDDI, bit reversed) */
+					/* [mM]F (FDDI) */
+					/* [mM]R (Bluetooth, bits reversed) */
 		return mac_address_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
 					 * 4:	1.2.3.4
Signature · 12 lines
1.7.9.5

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#12 lore raw

Re: [RFC] vsprintf: Add %pMR for Bluetooth MAC address

Hi Andrei,

Quoted 5 lines · * [email protected] <[email protected]>…

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

Quoted 7 lines

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
 lib/vsprintf.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Please resend this using the get-maintainers scripts in the --cc too (akpm et al) so we can get this to the right people.

Gustavo

#13 lore raw

Re: [RFC] vsprintf: Add %pMR for Bluetooth MAC address

In reply to [email protected]
Quoted 1 line · On Fri, 2012-05-25 at 17:32 +0300, [email protected] wrote:

From: Andrei Emeltchenko <[email protected]>

Hi Andrei.

Just trivia:

lib/vsprintf.c int kptr_restrict __read_mostly; · line 843

Quoted 5 lines
lib/vsprintf.c +1 -0
@@ -830,6 +840,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC Bluetooth address, bits reversed

Reverse order

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 905

Quoted 10 lines
lib/vsprintf.c +2 -1
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +901,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return resource_string(buf, end, ptr, spec, fmt);
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
-					/* [mM]F (FDDI, bit reversed) */
+					/* [mM]F (FDDI) */
+					/* [mM]R (Bluetooth, bits reversed) */

here too

#14 lore raw

PATCH v2 1/1 vsprintf: Add %pMR for Bluetooth MAC address

In reply to [email protected]

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
v2: changed bluetooth to reversed, syntax fixes

 lib/vsprintf.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
lib/vsprintf.c +17 -5
index abbabec..d98b12d 100644
@@ -557,17 +557,27 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 {
 	char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
 	char *p = mac_addr;
-	int i;
+	int i, index;
 	char separator;
+	bool reversed = false;
 
-	if (fmt[1] == 'F') {		/* FDDI canonical format */
+	switch (fmt[1]) {
+	case 'F':
 		separator = '-';
-	} else {
+		break;
+
+	case 'R':
+		reversed = true;
+		/* fall through */
+
+	default:
 		separator = ':';
+		break;
 	}
 
 	for (i = 0; i < 6; i++) {
-		p = hex_byte_pack(p, addr[i]);
+		index = !reversed ? i : 5 - i;
+		p = hex_byte_pack(p, addr[index]);
 		if (fmt[0] == 'M' && i != 5)
 			*p++ = separator;
 	}
@@ -830,6 +840,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +901,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return resource_string(buf, end, ptr, spec, fmt);
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
-					/* [mM]F (FDDI, bit reversed) */
+					/* [mM]F (FDDI) */
+					/* [mM]R (Reverse order; Bluetooth) */
 		return mac_address_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
 					 * 4:	1.2.3.4
Signature · 1 line
1.7.9.5
#15 lore raw

Re: [PATCHv2] vsprintf: Add %pMR for Bluetooth MAC address

Quoted 28 lines · Andrei Emeltchenko

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
       v2: changed bluetooth to reversed, syntax fixes

 lib/vsprintf.c |   22 +++++++++++++++++-----

 1 file changed, 17 insertions(+), 5 deletions(-)
lib/vsprintf.c +2 -1
index abbabec..d98b12d 100644
@@ -557,17 +557,27 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
  {
        char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
        char *p = mac_addr;
-       int i;
+       int i, index;
        char separator;
+       bool reversed = false;
 

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr, · line 571

Quoted 10 lines
lib/vsprintf.c +7 -2
-       if (fmt[1] == 'F') {            /* FDDI canonical format */
+       switch (fmt[1]) {
+       case 'F':
                separator = '-';
-       } else {
+               break;
+
+       case 'R':
+               reversed = true;
+               /* fall through */

This solution looks a bit limited. On one hand it makes difficult to add another case where format specifies colon separator with something else. On the other hand
I don't see any troubles if you allow reverse as a modifier for both cases %pMF & %pM

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr, · line 580

Quoted 10 lines
lib/vsprintf.c +5 -1
+
+       default:
                separator = ':';
+               break;
        }
 
        for (i = 0; i < 6; i++) {
-               p = hex_byte_pack(p, addr[i]);
+               index = !reversed ? i : 5 - i;
+               p = hex_byte_pack(p, addr[index]);

I guess instead of using additional variable (index), you could use just normal if () {} else {} sentence
here.

Quoted 21 lines
lib/vsprintf.c +1 -0
                if (fmt[0] == 'M' && i != 5)
                        *p++ = separator;
        }
@@ -830,6 +840,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +901,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
                return resource_string(buf, end, ptr, spec, fmt);

       case 'M':                       /* Colon separated: 00:01:02:03:04:05 */ case 'm':                       /* Contiguous: 000102030405 */
-                                       /* [mM]F (FDDI, bit reversed) */
+                                       /* [mM]F (FDDI) */
+                                       /* [mM]R (Reverse order; Bluetooth) */ return mac_address_string(buf, end, ptr, spec, fmt); case 'I':                       /* Formatted IP supported
                                        * 4:   1.2.3.4

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCHv2] vsprintf: Add %pMR for Bluetooth MAC address

Hi Andy,

Quoted 30 lines · Andy Shevchenko
Quoted 28 lines · Andrei Emeltchenko

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
       v2: changed bluetooth to reversed, syntax fixes

 lib/vsprintf.c |   22 +++++++++++++++++-----

 1 file changed, 17 insertions(+), 5 deletions(-)
lib/vsprintf.c +2 -1
index abbabec..d98b12d 100644
@@ -557,17 +557,27 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
  {
        char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
        char *p = mac_addr;
-       int i;
+       int i, index;
        char separator;
+       bool reversed = false;
 
Quoted 13 lines

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr, · line 571

Quoted 10 lines
lib/vsprintf.c +7 -2
-       if (fmt[1] == 'F') {            /* FDDI canonical format */
+       switch (fmt[1]) {
+       case 'F':
                separator = '-';
-       } else {
+               break;
+
+       case 'R':
+               reversed = true;
+               /* fall through */

This solution looks a bit limited. On one hand it makes difficult to add another case where format specifies colon separator with something else. On the other hand

I believe it is good as is for now. The other option would be to name it as "B" or "b" for bluetooth.

Quoted 2 lines

I don't see any troubles if you allow reverse as a modifier for both cases %pMF & %pM

MF is used for FDDI and it makes no sense to reverse it.

Quoted 7 lines
Quoted 7 lines
lib/vsprintf.c +3 -0
+
+       default:
                separator = ':';
+               break;
        }
 
Quoted 7 lines

lib/vsprintf.c char *mac_address_string(char *buf, char *end, u8 *addr, · line 580

Quoted 4 lines
lib/vsprintf.c +2 -1
        for (i = 0; i < 6; i++) {
-               p = hex_byte_pack(p, addr[i]);
+               index = !reversed ? i : 5 - i;
+               p = hex_byte_pack(p, addr[index]);

I guess instead of using additional variable (index), you could use just normal if () {} else {} sentence
here.

I can change this

Best regards
Andrei Emeltchenko

#17 lore raw

PATCH v3 1/1 vsprintf: Add %pMR for Bluetooth MAC address

In reply to Andy Shevchenko

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
v3: removed extra variable index
v2: changed bluetooth to reversed, syntax fixes

 lib/vsprintf.c |   23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
lib/vsprintf.c +19 -4
index abbabec..55052fa 100644
@@ -559,15 +559,28 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
 	char *p = mac_addr;
 	int i;
 	char separator;
+	bool reversed = false;
 
-	if (fmt[1] == 'F') {		/* FDDI canonical format */
+	switch (fmt[1]) {
+	case 'F':
 		separator = '-';
-	} else {
+		break;
+
+	case 'R':
+		reversed = true;
+		/* fall through */
+
+	default:
 		separator = ':';
+		break;
 	}
 
 	for (i = 0; i < 6; i++) {
-		p = hex_byte_pack(p, addr[i]);
+		if (reversed)
+			p = hex_byte_pack(p, addr[5 - i]);
+		else
+			p = hex_byte_pack(p, addr[i]);
+
 		if (fmt[0] == 'M' && i != 5)
 			*p++ = separator;
 	}
@@ -830,6 +843,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +904,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return resource_string(buf, end, ptr, spec, fmt);
 	case 'M':			/* Colon separated: 00:01:02:03:04:05 */
 	case 'm':			/* Contiguous: 000102030405 */
-					/* [mM]F (FDDI, bit reversed) */
+					/* [mM]F (FDDI) */
+					/* [mM]R (Reverse order; Bluetooth) */
 		return mac_address_string(buf, end, ptr, spec, fmt);
 	case 'I':			/* Formatted IP supported
 					 * 4:	1.2.3.4
Signature · 1 line
1.7.9.5
#18 lore raw

Re: [PATCHv3] vsprintf: Add %pMR for Bluetooth MAC address

ping

Quoted 77 lines · Andrei Emeltchenko

From: Andrei Emeltchenko <[email protected]>

Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function.

This is slightly modified version of Joe Perches <[email protected]> patch (sent Sat, Dec 4, 2010).

---
       v3: removed extra variable index
       v2: changed bluetooth to reversed, syntax fixes

 lib/vsprintf.c |   23 +++++++++++++++++++----

 1 file changed, 19 insertions(+), 4 deletions(-)
lib/vsprintf.c +17 -3
index abbabec..55052fa 100644
@@ -559,15 +559,28 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
        char *p = mac_addr;
        int i;
        char separator;
+       bool reversed = false;
 
-       if (fmt[1] == 'F') {            /* FDDI canonical format */
+       switch (fmt[1]) {
+       case 'F':
                separator = '-';
-       } else {
+               break;
+
+       case 'R':
+               reversed = true;
+               /* fall through */
+
+       default:
                separator = ':';
+               break;
        }
 
        for (i = 0; i < 6; i++) {
-               p = hex_byte_pack(p, addr[i]);
+               if (reversed)
+                       p = hex_byte_pack(p, addr[5 - i]);
+               else
+                       p = hex_byte_pack(p, addr[i]);
+
                if (fmt[0] == 'M' && i != 5)
                        *p++ = separator;
        }
@@ -830,6 +843,7 @@ int kptr_restrict __read_mostly;
  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
  *       with a dash-separated hex notation
+ * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -890,7 +904,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
                return resource_string(buf, end, ptr, spec, fmt);

       case 'M':                       /* Colon separated: 00:01:02:03:04:05 */ case 'm':                       /* Contiguous: 000102030405 */
-                                       /* [mM]F (FDDI, bit reversed) */
+                                       /* [mM]F (FDDI) */
+                                       /* [mM]R (Reverse order; Bluetooth) */ return mac_address_string(buf, end, ptr, spec, fmt); case 'I':                       /* Formatted IP supported
                                        * 4:   1.2.3.4
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#19 lore raw

PATCH 1/1 Docs: printk-formats: add description for %pMR

In reply to Andrei Emeltchenko

From: Andrei Emeltchenko <[email protected]>

Add information about new specifier %pMR for Bluetooth addresses.

---
 Documentation/printk-formats.txt |    5 +++++
 1 file changed, 5 insertions(+)
Documentation/printk-formats.txt +5 -0
index 5df176e..d8d168f 100644
@@ -56,6 +56,7 @@ Struct Resources:
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
+	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
 
@@ -67,6 +68,10 @@ MAC/FDDI addresses:
 	the 'M' specifier to use dash ('-') separators instead of the default
 	separator.
 
+	For Bluetooth addresses the 'R' specifier shall be used after the 'M'
+	specifier to use reversed byte order suitable for visual interpretation
+	of Bluetooth addresses which are in the little endian order.
+
 IPv4 addresses:
 
 	%pI4	1.2.3.4
Signature · 1 line
1.7.9.5
maintainer
#20 lore raw

Re: [PATCH] Docs: printk-formats: add description for %pMR

Quoted 17 lines · On Wed, 20 Jun 2012 13:44:49 +0300 Andrei Emeltchenko…

From: Andrei Emeltchenko <[email protected]>

Add information about new specifier %pMR for Bluetooth addresses.

...

Documentation/printk-formats.txt +1 -0
@@ -56,6 +56,7 @@ Struct Resources:
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
+	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
 

Documentation/printk-formats.txt MAC/FDDI addresses: · line 74

Quoted 7 lines
Documentation/printk-formats.txt +4 -0
@@ -67,6 +68,10 @@ MAC/FDDI addresses:
 	the 'M' specifier to use dash ('-') separators instead of the default
 	separator.
 
+	For Bluetooth addresses the 'R' specifier shall be used after the 'M'
+	specifier to use reversed byte order suitable for visual interpretation
+	of Bluetooth addresses which are in the little endian order.
+

huh, I didn't know about that file, or I forgot about it. I wonder if it is otherwise up to date.

Do we really need it? If we can sufficiently document the printk formats in lib/vsprintf.c then let's remove Documentation/printk-formats.txt. Otherwise, I shall do this:

lib/vsprintf.c +2 -0
@@ -1297,6 +1297,8 @@ qualifier:
  *   case.
  * %n is ignored
  *
+ * ** Please update Documentation/printk-formats.txt when making changes **
+ *
  * The return value is the number of characters which would
  * be generated for the given input, excluding the trailing
  * '\0', as per ISO C99. If you want to have the exact

_

#21 lore raw

Re: [PATCH] Docs: printk-formats: add description for %pMR

Hi,

Quoted 14 lines · Andrew Morton
Quoted 14 lines
Documentation/printk-formats.txt +1 -0
@@ -56,6 +56,7 @@ Struct Resources:
 MAC/FDDI addresses:
 
 	%pM	00:01:02:03:04:05
+	%pMR	05:04:03:02:01:00
 	%pMF	00-01-02-03-04-05
 	%pm	000102030405
 
@@ -67,6 +68,10 @@ MAC/FDDI addresses:
 	the 'M' specifier to use dash ('-') separators instead of the default
 	separator.
 
Quoted 6 lines

Documentation/printk-formats.txt MAC/FDDI addresses: · line 74

Quoted 4 lines
Documentation/printk-formats.txt +4 -0
+	For Bluetooth addresses the 'R' specifier shall be used after the 'M'
+	specifier to use reversed byte order suitable for visual interpretation
+	of Bluetooth addresses which are in the little endian order.
+

huh, I didn't know about that file, or I forgot about it.

This happens also to me.

Quoted 2 lines

I wonder if it is otherwise up to date.
Do we really need it?

I feel that the document is very good.

Quoted 3 lines

If we can sufficiently document the printk
formats in lib/vsprintf.c then let's remove
Documentation/printk-formats.txt.

Until I read that vsprintf.c I did not know where to find printk format specifiers. It does make sense to keep it.

lib/vsprintf.c qualifier: · line 1301

Quoted 11 lines

Otherwise, I shall do this:

lib/vsprintf.c +2 -0
@@ -1297,6 +1297,8 @@ qualifier:
  *   case.
  * %n is ignored
  *
+ * ** Please update Documentation/printk-formats.txt when making changes **
+ *

Looks good.

Best regards
Andrei Emeltchenko