Merge tag 'disintegrate-net-20121009' of git://git.infradead.org/users/dhowells/linux...
[pandora-kernel.git] / lib / vsprintf.c
index c2236f1..39c99fe 100644 (file)
@@ -180,19 +180,19 @@ char *put_dec_trunc8(char *buf, unsigned r)
                *buf++ = q - 10*r;
        }
 
-       q      = (r * 0x199a) >> 16;
-       *buf++ = (r - 10 * q)  + '0'; /* 6 */
+       q      = (r * 0x199a) >> 16;    /* r <= 9999 */
+       *buf++ = (r - 10 * q)  + '0';
        if (q == 0)
                return buf;
-       r      = (q * 0xcd) >> 11;
-       *buf++ = (q - 10 * r)  + '0'; /* 7 */
+       r      = (q * 0xcd) >> 11;      /* q <= 999 */
+       *buf++ = (q - 10 * r)  + '0';
        if (r == 0)
                return buf;
-       q      = (r * 0xcd) >> 11;
-       *buf++ = (r - 10 * q) + '0'; /* 8 */
+       q      = (r * 0xcd) >> 11;      /* r <= 99 */
+       *buf++ = (r - 10 * q) + '0';
        if (q == 0)
                return buf;
-       *buf++ = q + '0'; /* 9 */
+       *buf++ = q + '0';                /* q <= 9 */
        return buf;
 }
 
@@ -987,7 +987,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)
+ * - '[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
@@ -1338,7 +1338,10 @@ qualifier:
  * %pR output the address range in a struct resource with decoded flags
  * %pr output the address range in a struct resource with raw flags
  * %pM output a 6-byte MAC address with colons
+ * %pMR output a 6-byte MAC address with colons in reversed order
+ * %pMF output a 6-byte MAC address with dashes
  * %pm output a 6-byte MAC address without colons
+ * %pmR output a 6-byte MAC address without colons in reversed order
  * %pI4 print an IPv4 address without leading zeros
  * %pi4 print an IPv4 address with leading zeros
  * %pI6 print an IPv6 address with colons
@@ -2014,7 +2017,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
        s16 field_width;
        bool is_sign;
 
-       while (*fmt && *str) {
+       while (*fmt) {
                /* skip any white space in format */
                /* white space in format matchs any amount of
                 * white space, including none, in the input.
@@ -2039,6 +2042,8 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
                 * advance both strings to next white space
                 */
                if (*fmt == '*') {
+                       if (!*str)
+                               break;
                        while (!isspace(*fmt) && *fmt != '%' && *fmt)
                                fmt++;
                        while (!isspace(*str) && *str)
@@ -2067,7 +2072,17 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
                        }
                }
 
-               if (!*fmt || !*str)
+               if (!*fmt)
+                       break;
+
+               if (*fmt == 'n') {
+                       /* return number of characters read so far */
+                       *va_arg(args, int *) = str - buf;
+                       ++fmt;
+                       continue;
+               }
+
+               if (!*str)
                        break;
 
                base = 10;
@@ -2100,13 +2115,6 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
                        num++;
                }
                continue;
-               case 'n':
-                       /* return number of characters read so far */
-               {
-                       int *i = (int *)va_arg(args, int*);
-                       *i = str - buf;
-               }
-               continue;
                case 'o':
                        base = 8;
                        break;
@@ -2207,16 +2215,6 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
                str = next;
        }
 
-       /*
-        * Now we've come all the way through so either the input string or the
-        * format ended. In the former case, there can be a %n at the current
-        * position in the format that needs to be filled.
-        */
-       if (*fmt == '%' && *(fmt + 1) == 'n') {
-               int *p = (int *)va_arg(args, int *);
-               *p = str - buf;
-       }
-
        return num;
 }
 EXPORT_SYMBOL(vsscanf);