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 --
Save some text and bss.
Remove function batostr so there's no possibility of bad output.
from the net/bluetooth directory:
$ size built-in.o.*
text data bss dec hex filename
293562 16265 70088 379915 5cc0b built-in.o.allyesconfig.new
294619 16269 70480 381368 5d1b8 built-in.o.allyesconfig.old
30359 772 56 31187 79d3 built-in.o.btonly.new
30555 776 92 31423 7abf built-in.o.btonly.old
Signed-off-by: Joe Perches <joe@perches.com>
---
net/bluetooth/bnep/core.c | 3 +--
net/bluetooth/cmtp/core.c | 2 +-
net/bluetooth/hci_conn.c | 6 +++---
net/bluetooth/hci_core.c | 8 ++++----
net/bluetooth/hci_event.c | 6 +++---
net/bluetooth/hci_sysfs.c | 10 +++++-----
net/bluetooth/hidp/core.c | 4 ++--
net/bluetooth/l2cap.c | 19 +++++++++----------
net/bluetooth/lib.c | 14 --------------
net/bluetooth/rfcomm/core.c | 16 ++++++++--------
net/bluetooth/rfcomm/sock.c | 8 ++++----
net/bluetooth/rfcomm/tty.c | 6 +++---
net/bluetooth/sco.c | 12 ++++++------
13 files changed, 49 insertions(+), 65 deletions(-)
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 5868597..3d4530f 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -199,8 +199,7 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len)
memcpy(a1, data, ETH_ALEN); data += ETH_ALEN;
a2 = data; data += ETH_ALEN;
- BT_DBG("mc filter %s -> %s",
- batostr((void *) a1), batostr((void *) a2));
+ BT_DBG("mc filter %pMbt -> %pMbt", a1, a2);
#define INCA(a) { int i = 5; while (i >=0 && ++a[i--] == 0); }
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 8e5f292..f72bca7 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -344,7 +344,7 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
BT_DBG("mtu %d", session->mtu);
...Hi Joe, 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 --
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. --
Hi Joe, 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 --
Bluetooth output the MAC address in reverse order.
Bluetooth memory order: 00 01 02 03 04 05 is output "05:04:03:02:01:00".
This can save overall text when bluetooth is compiled in.
Bluetooth currently uses a very slightly unsafe local function (batostr)
to output these formatted addresses.
Adding %pMbt allows the batostr function to be removed.
For x86:
$ size lib/vsprintf*.o*
text data bss dec hex filename
8189 0 2 8191 1fff lib/vsprintf.o.defconfig.new
8150 0 2 8152 1fd8 lib/vsprintf.o.defconfig.old
18633 56 3936 22625 5861 lib/vsprintf.o.allyesconfig.new
18571 56 3920 22547 5813 lib/vsprintf.o.allyesconfig.old
Signed-off-by: Joe Perches <joe@perches.com>
---
lib/vsprintf.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3d..9346ed9 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -700,15 +700,18 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
char *p = mac_addr;
int i;
char separator;
+ bool bluetooth = false;
if (fmt[1] == 'F') { /* FDDI canonical format */
separator = '-';
} else {
separator = ':';
+ if (fmt[1] == 'b' && fmt[2] == 't')
+ bluetooth = true;
}
for (i = 0; i < 6; i++) {
- p = pack_hex_byte(p, addr[i]);
+ p = pack_hex_byte(p, addr[!bluetooth ? i : 5 - i]);
if (fmt[0] == 'M' && i != 5)
*p++ = separator;
}
@@ -1012,6 +1015,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'M': /* Colon separated: 00:01:02:03:04:05 */
case 'm': /* Contiguous: 000102030405 */
/* [mM]F (FDDI, bit reversed) */
+ /* [mM]bt (Bluetooth, index:543210) */
return mac_address_string(buf, end, ptr, spec, fmt);
case 'I': /* Formatted IP supported
* 4: 1.2.3.4
--
1.7.3.2.245.g03276.dirty
--
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 --
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. --
Hi Joe, Looks good to me. Acked-by: Gustavo F. Padovan <padovan@profusion.mobi> -- Gustavo F. Padovan http://profusion.mobi --
