From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-bluetooth@vger.kernel.org, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, adobriyan@gmail.com,
andriy.shevchenko@linux.intel.com
Subject: Re: [PATCHv2] vsprintf: Add %pMR for Bluetooth MAC address
Date: Mon, 28 May 2012 13:20:57 +0300 [thread overview]
Message-ID: <20120528102055.GA3537@aemeltch-MOBL1> (raw)
In-Reply-To: <CAHp75Vc3sut7R7FF=xHQ0-3HaydPBh86sNnzRjKP8+ow=SOfLg@mail.gmail.com>
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
> <Andrei.Emeltchenko.news@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > 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 <joe@perches.com>
> > patch (sent Sat, Dec 4, 2010).
> >
> > Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> > ---
> > 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
next prev parent reply other threads:[~2012-05-28 10:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-04 2:33 [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Joe Perches
2010-12-04 2:33 ` [PATCH 2/2] bluetooth: Use printf extension %pMbt Joe Perches
2010-12-06 18:15 ` Gustavo F. Padovan
2010-12-06 18:50 ` Joe Perches
2010-12-06 20:07 ` Gustavo F. Padovan
2012-05-09 9:01 ` [PATCH 0/2] Add and use vsprintf extension %pMbt for bluetooth macs Andrei Emeltchenko
2012-05-11 23:21 ` Joe Perches
2012-05-25 14:32 ` [RFC] vsprintf: Add %pMR for Bluetooth MAC address andrei.emeltchenko.news
2012-05-25 14:37 ` Gustavo Padovan
2012-05-25 15:07 ` Joe Perches
2012-05-28 9:00 ` [PATCHv2] " Andrei Emeltchenko
2012-05-28 10:01 ` Andy Shevchenko
2012-05-28 10:20 ` Andrei Emeltchenko [this message]
2012-05-28 13:05 ` [PATCHv3] " Andrei Emeltchenko
2012-06-05 11:57 ` Andrei Emeltchenko
2012-06-20 10:44 ` [PATCH] Docs: printk-formats: add description for %pMR Andrei Emeltchenko
2012-06-20 21:19 ` Andrew Morton
2012-06-21 7:08 ` Andrei Emeltchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120528102055.GA3537@aemeltch-MOBL1 \
--to=andrei.emeltchenko.news@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).