ALSA: oxygen: add self-documenting functions
[safe/jmp/linux-2.6] / lib / vsprintf.c
index f569feb..c399bc1 100644 (file)
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/kernel.h>
+#include <linux/kallsyms.h>
+#include <linux/uaccess.h>
 
 #include <asm/page.h>          /* for PAGE_SIZE */
 #include <asm/div64.h>
+#include <asm/sections.h>      /* for dereference_function_descriptor() */
 
 /* Works only for digits and letters, but small and fast */
 #define TOLOWER(x) ((x) | 0x20)
@@ -218,7 +221,7 @@ int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
        if (len == 0)                                                   \
                return -EINVAL;                                         \
                                                                        \
-       val = simple_strtoul(cp, &tail, base);                          \
+       val = simple_strtou##type(cp, &tail, base);                     \
        if ((*tail == '\0') ||                                          \
                ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
                *res = val;                                             \
@@ -511,8 +514,42 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio
        return buf;
 }
 
-static char *pointer(char *buf, char *end, void *ptr, int field_width, int precision, int flags)
+static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int precision, int flags)
 {
+       unsigned long value = (unsigned long) ptr;
+#ifdef CONFIG_KALLSYMS
+       char sym[KSYM_SYMBOL_LEN];
+       sprint_symbol(sym, value);
+       return string(buf, end, sym, field_width, precision, flags);
+#else
+       field_width = 2*sizeof(void *);
+       flags |= SPECIAL | SMALL | ZEROPAD;
+       return number(buf, end, value, 16, field_width, precision, flags);
+#endif
+}
+
+/*
+ * Show a '%p' thing.  A kernel extension is that the '%p' is followed
+ * by an extra set of alphanumeric characters that are extended format
+ * specifiers.
+ *
+ * Right now we just handle 'F' (for symbolic Function descriptor pointers)
+ * and 'S' (for Symbolic direct pointers), but this can easily be
+ * extended in the future (network address types etc).
+ *
+ * The difference between 'S' and 'F' is that on ia64 and ppc64 function
+ * pointers are really function descriptors, which contain a pointer the
+ * real address. 
+ */
+static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
+{
+       switch (*fmt) {
+       case 'F':
+               ptr = dereference_function_descriptor(ptr);
+               /* Fallthrough */
+       case 'S':
+               return symbol_string(buf, end, ptr, field_width, precision, flags);
+       }
        flags |= SMALL;
        if (field_width == -1) {
                field_width = 2*sizeof(void *);
@@ -663,7 +700,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
                                continue;
 
                        case 'p':
-                               str = pointer(str, end, va_arg(args, void *), field_width, precision, flags);
+                               str = pointer(fmt+1, str, end,
+                                               va_arg(args, void *),
+                                               field_width, precision, flags);
+                               /* Skip all alphanumeric pointer suffixes */
+                               while (isalnum(fmt[1]))
+                                       fmt++;
                                continue;
 
                        case 'n':