diff options
author | Joe Perches <joe@perches.com> | 2014-01-23 18:54:17 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-23 19:36:56 -0500 |
commit | aaf07621b8bbfdc0d87e9e5dbf1af3b24304998a (patch) | |
tree | 0b6b96f278a12b3dc5bcc46217ea8f0d54098d14 | |
parent | c28aa1f0a847c36daa4280b611e2b54bad75c576 (diff) |
vsprintf: add %pad extension for dma_addr_t use
dma_addr_t's can be either u32 or u64 depending on a CONFIG option.
There are a few hundred dma_addr_t's printed via either cast to unsigned
long long, unsigned long or no cast at all.
Add %pad to be able to emit them without the cast.
Update Documentation/printk-formats.txt too.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: "Shevchenko, Andriy" <andriy.shevchenko@intel.com>
Cc: Rob Landley <rob@landley.net>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | Documentation/printk-formats.txt | 11 | ||||
-rw-r--r-- | lib/vsprintf.c | 33 |
2 files changed, 36 insertions, 8 deletions
diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index 445ad743ec81..6f4eb322ffaf 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt | |||
@@ -55,14 +55,21 @@ Struct Resources: | |||
55 | For printing struct resources. The 'R' and 'r' specifiers result in a | 55 | For printing struct resources. The 'R' and 'r' specifiers result in a |
56 | printed resource with ('R') or without ('r') a decoded flags member. | 56 | printed resource with ('R') or without ('r') a decoded flags member. |
57 | 57 | ||
58 | Physical addresses: | 58 | Physical addresses types phys_addr_t: |
59 | 59 | ||
60 | %pa 0x01234567 or 0x0123456789abcdef | 60 | %pa[p] 0x01234567 or 0x0123456789abcdef |
61 | 61 | ||
62 | For printing a phys_addr_t type (and its derivatives, such as | 62 | For printing a phys_addr_t type (and its derivatives, such as |
63 | resource_size_t) which can vary based on build options, regardless of | 63 | resource_size_t) which can vary based on build options, regardless of |
64 | the width of the CPU data path. Passed by reference. | 64 | the width of the CPU data path. Passed by reference. |
65 | 65 | ||
66 | DMA addresses types dma_addr_t: | ||
67 | |||
68 | %pad 0x01234567 or 0x0123456789abcdef | ||
69 | |||
70 | For printing a dma_addr_t type which can vary based on build options, | ||
71 | regardless of the width of the CPU data path. Passed by reference. | ||
72 | |||
66 | Raw buffer as a hex string: | 73 | Raw buffer as a hex string: |
67 | %*ph 00 01 02 ... 3f | 74 | %*ph 00 01 02 ... 3f |
68 | %*phC 00:01:02: ... :3f | 75 | %*phC 00:01:02: ... :3f |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 10909c571494..185b6d300ebc 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -1155,6 +1155,30 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr, | |||
1155 | return number(buf, end, *(const netdev_features_t *)addr, spec); | 1155 | return number(buf, end, *(const netdev_features_t *)addr, spec); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | static noinline_for_stack | ||
1159 | char *address_val(char *buf, char *end, const void *addr, | ||
1160 | struct printf_spec spec, const char *fmt) | ||
1161 | { | ||
1162 | unsigned long long num; | ||
1163 | |||
1164 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | ||
1165 | spec.base = 16; | ||
1166 | |||
1167 | switch (fmt[1]) { | ||
1168 | case 'd': | ||
1169 | num = *(const dma_addr_t *)addr; | ||
1170 | spec.field_width = sizeof(dma_addr_t) * 2 + 2; | ||
1171 | break; | ||
1172 | case 'p': | ||
1173 | default: | ||
1174 | num = *(const phys_addr_t *)addr; | ||
1175 | spec.field_width = sizeof(phys_addr_t) * 2 + 2; | ||
1176 | break; | ||
1177 | } | ||
1178 | |||
1179 | return number(buf, end, num, spec); | ||
1180 | } | ||
1181 | |||
1158 | int kptr_restrict __read_mostly; | 1182 | int kptr_restrict __read_mostly; |
1159 | 1183 | ||
1160 | /* | 1184 | /* |
@@ -1218,7 +1242,8 @@ int kptr_restrict __read_mostly; | |||
1218 | * N no separator | 1242 | * N no separator |
1219 | * The maximum supported length is 64 bytes of the input. Consider | 1243 | * The maximum supported length is 64 bytes of the input. Consider |
1220 | * to use print_hex_dump() for the larger input. | 1244 | * to use print_hex_dump() for the larger input. |
1221 | * - 'a' For a phys_addr_t type and its derivative types (passed by reference) | 1245 | * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives |
1246 | * (default assumed to be phys_addr_t, passed by reference) | ||
1222 | * - 'd[234]' For a dentry name (optionally 2-4 last components) | 1247 | * - 'd[234]' For a dentry name (optionally 2-4 last components) |
1223 | * - 'D[234]' Same as 'd' but for a struct file | 1248 | * - 'D[234]' Same as 'd' but for a struct file |
1224 | * | 1249 | * |
@@ -1353,11 +1378,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
1353 | } | 1378 | } |
1354 | break; | 1379 | break; |
1355 | case 'a': | 1380 | case 'a': |
1356 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 1381 | return address_val(buf, end, ptr, spec, fmt); |
1357 | spec.field_width = sizeof(phys_addr_t) * 2 + 2; | ||
1358 | spec.base = 16; | ||
1359 | return number(buf, end, | ||
1360 | (unsigned long long) *((phys_addr_t *)ptr), spec); | ||
1361 | case 'd': | 1382 | case 'd': |
1362 | return dentry_name(buf, end, ptr, spec, fmt); | 1383 | return dentry_name(buf, end, ptr, spec, fmt); |
1363 | case 'D': | 1384 | case 'D': |