staging/rdma/hfi1: Remove spurious error messages
[deliverable/linux.git] / lib / vsprintf.c
index e966a45e2f00d8d277eda0cbdf9fcc65ed0bbbc3..f9cee8e1233c0fe0f626fe2680ca4b9ff9d3153e 100644 (file)
@@ -1448,7 +1448,6 @@ int kptr_restrict __read_mostly;
  * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
  *        (legacy clock framework) of the clock
  * - 'Cr' For a clock, it prints the current rate of the clock
- * - 'n' For ignored argument
  *
  * ** Please update also Documentation/printk-formats.txt when making changes **
  *
@@ -1460,7 +1459,7 @@ static noinline_for_stack
 char *pointer(const char *fmt, char *buf, char *end, void *ptr,
              struct printf_spec spec)
 {
-       int default_width = 2 * sizeof(void *) + (spec.flags & SPECIAL ? 2 : 0);
+       const int default_width = 2 * sizeof(void *);
 
        if (!ptr && *fmt != 'K') {
                /*
@@ -1772,14 +1771,14 @@ qualifier:
 
        case 'n':
                /*
-                * Since %n poses a greater security risk than utility, treat
-                * it as an invalid format specifier. Warn about its use so
-                * that new instances don't get added.
+                * Since %n poses a greater security risk than
+                * utility, treat it as any other invalid or
+                * unsupported format specifier.
                 */
-               WARN_ONCE(1, "Please remove ignored %%n in '%s'\n", fmt);
                /* Fall-through */
 
        default:
+               WARN_ONCE(1, "Please remove unsupported %%%c in format string\n", *fmt);
                spec->type = FORMAT_TYPE_INVALID;
                return fmt - start;
        }
@@ -1814,8 +1813,10 @@ qualifier:
  * @fmt: The format string to use
  * @args: Arguments for the format string
  *
- * This function follows C99 vsnprintf, but has some extensions:
- * %n is ignored
+ * This function generally follows C99 vsnprintf, but has some
+ * extensions and a few limitations:
+ *
+ * %n is unsupported
  * %p* is handled by pointer()
  *
  * See pointer() or Documentation/printk-formats.txt for more
@@ -1920,10 +1921,15 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
                        break;
 
                case FORMAT_TYPE_INVALID:
-                       if (str < end)
-                               *str = '%';
-                       ++str;
-                       break;
+                       /*
+                        * Presumably the arguments passed gcc's type
+                        * checking, but there is no safe or sane way
+                        * for us to continue parsing the format and
+                        * fetching from the va_list; the remaining
+                        * specifiers and arguments would be out of
+                        * sync.
+                        */
+                       goto out;
 
                default:
                        switch (spec.type) {
@@ -1968,6 +1974,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
                }
        }
 
+out:
        if (size > 0) {
                if (str < end)
                        *str = '\0';
@@ -2165,9 +2172,10 @@ do {                                                                     \
 
                switch (spec.type) {
                case FORMAT_TYPE_NONE:
-               case FORMAT_TYPE_INVALID:
                case FORMAT_TYPE_PERCENT_CHAR:
                        break;
+               case FORMAT_TYPE_INVALID:
+                       goto out;
 
                case FORMAT_TYPE_WIDTH:
                case FORMAT_TYPE_PRECISION:
@@ -2229,6 +2237,7 @@ do {                                                                      \
                }
        }
 
+out:
        return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
 #undef save_arg
 }
@@ -2262,7 +2271,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
        char *str, *end;
        const char *args = (const char *)bin_buf;
 
-       if (WARN_ON_ONCE((int) size < 0))
+       if (WARN_ON_ONCE(size > INT_MAX))
                return 0;
 
        str = buf;
@@ -2351,12 +2360,14 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
                        break;
 
                case FORMAT_TYPE_PERCENT_CHAR:
-               case FORMAT_TYPE_INVALID:
                        if (str < end)
                                *str = '%';
                        ++str;
                        break;
 
+               case FORMAT_TYPE_INVALID:
+                       goto out;
+
                default: {
                        unsigned long long num;
 
@@ -2399,6 +2410,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
                } /* switch(spec.type) */
        } /* while(*fmt) */
 
+out:
        if (size > 0) {
                if (str < end)
                        *str = '\0';
This page took 0.039794 seconds and 5 git commands to generate.