2010-12-04 02:33:14

by Joe Perches

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
1.7.3.2.245.g03276.dirty


2010-12-04 02:33:22

by Joe Perches

[permalink] [raw]
Subject: [PATCH 2/2] bluetooth: Use printf extension %pMbt

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 <[email protected]>
---
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

2010-12-04 02:33:38

by Joe Perches

[permalink] [raw]
Subject: [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

Signed-off-by: Joe Perches <[email protected]>
---
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

2010-12-04 11:03:53

by Michał Mirosław

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

2010/12/4 Joe Perches <[email protected]>:
> 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

2010-12-04 17:48:54

by Joe Perches

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

On Sat, 2010-12-04 at 12:03 +0100, Michał Mirosław wrote:
> 2010/12/4 Joe Perches <[email protected]>:
> > 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.

2010-12-06 18:11:12

by Gustavo Padovan

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

Hi Joe,

* Joe Perches <[email protected]> [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 <[email protected]>

Looks good to me.

Acked-by: Gustavo F. Padovan <[email protected]>

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

2010-12-06 18:14:50

by Gustavo Padovan

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

Hi Joe,

* Joe Perches <[email protected]> [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 <[email protected]>
> ---
> 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

2010-12-06 18:50:17

by Joe Perches

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

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.

2010-12-06 20:07:36

by Gustavo Padovan

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

Hi Joe,

* Joe Perches <[email protected]> [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

2012-05-09 09:00:52

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs

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

2012-05-11 23:21:29

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs

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.

2012-05-25 14:32:10

by Andrei Emeltchenko

[permalink] [raw]
Subject: [RFC] 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).

Signed-off-by: Andrei Emeltchenko <[email protected]>
---
lib/vsprintf.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index abbabec..b767c3c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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
--
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.

2012-05-25 14:37:53

by Gustavo Padovan

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

Hi Andrei,

* [email protected] <[email protected]> [2012-05-25 17:32:48 +0300]:

> 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).
>
> Signed-off-by: Andrei Emeltchenko <[email protected]>
> ---
> 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

2012-05-25 15:07:21

by Joe Perches

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

On Fri, 2012-05-25 at 17:32 +0300, [email protected]
wrote:
> From: Andrei Emeltchenko <[email protected]>

Hi Andrei.

Just trivia:

> @@ -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

> * - '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

2012-05-28 08:59:54

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2] 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).

Signed-off-by: Andrei Emeltchenko <[email protected]>
---
v2: changed bluetooth to reversed, syntax fixes

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

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index abbabec..d98b12d 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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
--
1.7.9.5

2012-05-28 10:01:09

by Andy Shevchenko

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

On Mon, May 28, 2012 at 12:00 PM, Andrei Emeltchenko
<[email protected]> wrote:
> 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).
>
> Signed-off-by: Andrei Emeltchenko <[email protected]>
> ---
>        v2: changed bluetooth to reversed, syntax fixes
>
>  lib/vsprintf.c |   22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index abbabec..d98b12d 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -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 */
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

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

>                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



--
With Best Regards,
Andy Shevchenko

2012-05-28 10:19:45

by Andrei Emeltchenko

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

Hi Andy,

On Mon, May 28, 2012 at 01:01:05PM +0300, Andy Shevchenko wrote:
> On Mon, May 28, 2012 at 12:00 PM, Andrei Emeltchenko
> <[email protected]> wrote:
> > 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).
> >
> > Signed-off-by: Andrei Emeltchenko <[email protected]>
> > ---
> > ? ? ? ?v2: changed bluetooth to reversed, syntax fixes
> >
> > ?lib/vsprintf.c | ? 22 +++++++++++++++++-----
> > ?1 file changed, 17 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index abbabec..d98b12d 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -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 */
> 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.

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

>
> > +
> > + ? ? ? 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.

I can change this

Best regards
Andrei Emeltchenko

2012-05-28 13:04:06

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3] 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).

Signed-off-by: Andrei Emeltchenko <[email protected]>
---
v3: removed extra variable index
v2: changed bluetooth to reversed, syntax fixes

lib/vsprintf.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index abbabec..55052fa 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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

2012-06-05 11:57:27

by Andrei Emeltchenko

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

ping

On Mon, May 28, 2012 at 4:05 PM, Andrei Emeltchenko
<[email protected]> wrote:
> 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).
>
> Signed-off-by: Andrei Emeltchenko <[email protected]>
> ---
> ? ? ? ?v3: removed extra variable index
> ? ? ? ?v2: changed bluetooth to reversed, syntax fixes
>
> ?lib/vsprintf.c | ? 23 +++++++++++++++++++----
> ?1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index abbabec..55052fa 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -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

2012-06-20 10:43:19

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH] Docs: printk-formats: add description for %pMR

From: Andrei Emeltchenko <[email protected]>

Add information about new specifier %pMR for Bluetooth addresses.

Signed-off-by: Andrei Emeltchenko <[email protected]>
---
Documentation/printk-formats.txt | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 5df176e..d8d168f 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -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
--
1.7.9.5

2012-06-20 21:20:00

by Andrew Morton

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

On Wed, 20 Jun 2012 13:44:49 +0300
Andrei Emeltchenko <[email protected]> wrote:

> From: Andrei Emeltchenko <[email protected]>
>
> Add information about new specifier %pMR for Bluetooth addresses.
>
> ...
>
> --- a/Documentation/printk-formats.txt
> +++ b/Documentation/printk-formats.txt
> @@ -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.
> +

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:


--- a/lib/vsprintf.c
+++ a/lib/vsprintf.c
@@ -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
_

2012-06-21 07:07:08

by Andrei Emeltchenko

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

Hi,

On Wed, Jun 20, 2012 at 02:19:57PM -0700, Andrew Morton wrote:
> > --- a/Documentation/printk-formats.txt
> > +++ b/Documentation/printk-formats.txt
> > @@ -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.
> > +
>
> huh, I didn't know about that file, or I forgot about it.

This happens also to me.

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

I feel that the document is very good.

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

> Otherwise, I shall do this:
>
>
> --- a/lib/vsprintf.c
> +++ a/lib/vsprintf.c
> @@ -1297,6 +1297,8 @@ qualifier:
> * case.
> * %n is ignored
> *
> + * ** Please update Documentation/printk-formats.txt when making changes **
> + *

Looks good.

Best regards
Andrei Emeltchenko