From patchwork Sat Dec 4 02:33:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 74233 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8FC0CB70B0 for ; Sat, 4 Dec 2010 13:34:19 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754545Ab0LDCdh (ORCPT ); Fri, 3 Dec 2010 21:33:37 -0500 Received: from mail.perches.com ([173.55.12.10]:2206 "EHLO mail.perches.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754235Ab0LDCdN (ORCPT ); Fri, 3 Dec 2010 21:33:13 -0500 Received: from Joe-Laptop.home (unknown [192.168.1.162]) by mail.perches.com (Postfix) with ESMTP id 95B692436C; Fri, 3 Dec 2010 18:33:06 -0800 (PST) From: Joe Perches To: Marcel Holtmann , "Gustavo F. Padovan" , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org Subject: [PATCH 1/2] vsprintf: Add %pMbt, bluetooth mac address Date: Fri, 3 Dec 2010 18:33:03 -0800 Message-Id: X-Mailer: git-send-email 1.7.3.2.245.g03276.dirty In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Gustavo F. Padovan --- 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