aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStepan Moskovchenko <stepanm@codeaurora.org>2013-02-21 19:43:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 20:22:20 -0500
commit7d7992108d02aa92ad4c77e5d9ce14088c942e75 (patch)
treeefa7e3cbbac8f7fde794f0062d98420b551697c6
parentf3cbd435b02fb45efc2c8a39c2ea19816669c412 (diff)
lib/vsprintf.c: add %pa format specifier for phys_addr_t types
Add the %pa format specifier for printing a phys_addr_t type and its derivative types (such as resource_size_t), since the physical address size on some platforms can vary based on build options, regardless of the native integer type. Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org> Cc: Rob Landley <rob@landley.net> Cc: George Spelvin <linux@horizon.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Stephen Boyd <sboyd@codeaurora.org> Cc: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/printk-formats.txt14
-rw-r--r--lib/vsprintf.c7
2 files changed, 18 insertions, 3 deletions
diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 8ffb274367c7..e8a6aa473bab 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -53,6 +53,14 @@ Struct Resources:
53 For printing struct resources. The 'R' and 'r' specifiers result in a 53 For printing struct resources. The 'R' and 'r' specifiers result in a
54 printed resource with ('R') or without ('r') a decoded flags member. 54 printed resource with ('R') or without ('r') a decoded flags member.
55 55
56Physical addresses:
57
58 %pa 0x01234567 or 0x0123456789abcdef
59
60 For printing a phys_addr_t type (and its derivatives, such as
61 resource_size_t) which can vary based on build options, regardless of
62 the width of the CPU data path. Passed by reference.
63
56Raw buffer as a hex string: 64Raw buffer as a hex string:
57 %*ph 00 01 02 ... 3f 65 %*ph 00 01 02 ... 3f
58 %*phC 00:01:02: ... :3f 66 %*phC 00:01:02: ... :3f
@@ -150,9 +158,9 @@ s64 SHOULD be printed with %lld/%llx, (long long):
150 printk("%lld", (long long)s64_var); 158 printk("%lld", (long long)s64_var);
151 159
152If <type> is dependent on a config option for its size (e.g., sector_t, 160If <type> is dependent on a config option for its size (e.g., sector_t,
153blkcnt_t, phys_addr_t, resource_size_t) or is architecture-dependent 161blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
154for its size (e.g., tcflag_t), use a format specifier of its largest 162format specifier of its largest possible type and explicitly cast to it.
155possible type and explicitly cast to it. Example: 163Example:
156 164
157 printk("test: sector number/total blocks: %llu/%llu\n", 165 printk("test: sector number/total blocks: %llu/%llu\n",
158 (unsigned long long)sector, (unsigned long long)blockcount); 166 (unsigned long long)sector, (unsigned long long)blockcount);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index fab33a9c5318..0d62fd700f68 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1030,6 +1030,7 @@ int kptr_restrict __read_mostly;
1030 * N no separator 1030 * N no separator
1031 * The maximum supported length is 64 bytes of the input. Consider 1031 * The maximum supported length is 64 bytes of the input. Consider
1032 * to use print_hex_dump() for the larger input. 1032 * to use print_hex_dump() for the larger input.
1033 * - 'a' For a phys_addr_t type and its derivative types (passed by reference)
1033 * 1034 *
1034 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 1035 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
1035 * function pointers are really function descriptors, which contain a 1036 * function pointers are really function descriptors, which contain a
@@ -1120,6 +1121,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1120 return netdev_feature_string(buf, end, ptr, spec); 1121 return netdev_feature_string(buf, end, ptr, spec);
1121 } 1122 }
1122 break; 1123 break;
1124 case 'a':
1125 spec.flags |= SPECIAL | SMALL | ZEROPAD;
1126 spec.field_width = sizeof(phys_addr_t) * 2 + 2;
1127 spec.base = 16;
1128 return number(buf, end,
1129 (unsigned long long) *((phys_addr_t *)ptr), spec);
1123 } 1130 }
1124 spec.flags |= SMALL; 1131 spec.flags |= SMALL;
1125 if (spec.field_width == -1) { 1132 if (spec.field_width == -1) {