Re: [PATCH] lib/vsprintf.c: Add %pMF to format FDDI bit reversed MAC addresses
From: Michał Mirosław
Date: Thu Jan 07 2010 - 16:19:07 EST
2010/1/7 Joe Perches <joe@xxxxxxxxxxx>:
[...]
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index d4996cf..36959cc 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -25,6 +25,7 @@
> #include <linux/kallsyms.h>
> #include <linux/uaccess.h>
> #include <linux/ioport.h>
> +#include <linux/bitrev.h>
> #include <net/addrconf.h>
>
> #include <asm/page.h> /* for PAGE_SIZE */
> @@ -675,17 +676,37 @@ static char *resource_string(char *buf, char *end, struct resource *res,
> return string(buf, end, sym, spec);
> }
>
> +static u8 mac_byte(u8 val)
> +{
> + return val;
> +}
> +
> +static u8 mac_byte_rev(u8 val)
> +{
> + return bitrev8(val);
> +}
> +
> static char *mac_address_string(char *buf, char *end, u8 *addr,
> struct printf_spec spec, const char *fmt)
> {
> char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
> char *p = mac_addr;
> int i;
> + u8 (*mac_byte_fn)(u8 val);
> + char separator;
> +
> + if (fmt[1] == 'F') { /* FDDI canonical format */
> + mac_byte_fn = mac_byte_rev;
> + separator = '-';
> + } else {
> + mac_byte_fn = mac_byte;
> + separator = ':';
> + }
>
> for (i = 0; i < 6; i++) {
> - p = pack_hex_byte(p, addr[i]);
> + p = pack_hex_byte(p, mac_byte_fn(addr[i]));
> if (fmt[0] == 'M' && i != 5)
> - *p++ = ':';
> + *p++ = separator;
> }
> *p = '\0';
>
[...]
Something like the following might be smaller and faster - no
functions and their calls (just an idea);
int rev = (fmt[1] == 'F');
...
p = pack_hex_byte(p, rev ? bitrev8(addr[i]) : addr[i]);
Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/