Commit aaf07621 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

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: default avatarJoe 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c28aa1f0
...@@ -55,14 +55,21 @@ Struct Resources: ...@@ -55,14 +55,21 @@ Struct Resources:
For printing struct resources. The 'R' and 'r' specifiers result in a For printing struct resources. The 'R' and 'r' specifiers result in a
printed resource with ('R') or without ('r') a decoded flags member. printed resource with ('R') or without ('r') a decoded flags member.
Physical addresses: Physical addresses types phys_addr_t:
%pa 0x01234567 or 0x0123456789abcdef %pa[p] 0x01234567 or 0x0123456789abcdef
For printing a phys_addr_t type (and its derivatives, such as For printing a phys_addr_t type (and its derivatives, such as
resource_size_t) which can vary based on build options, regardless of resource_size_t) which can vary based on build options, regardless of
the width of the CPU data path. Passed by reference. the width of the CPU data path. Passed by reference.
DMA addresses types dma_addr_t:
%pad 0x01234567 or 0x0123456789abcdef
For printing a dma_addr_t type which can vary based on build options,
regardless of the width of the CPU data path. Passed by reference.
Raw buffer as a hex string: Raw buffer as a hex string:
%*ph 00 01 02 ... 3f %*ph 00 01 02 ... 3f
%*phC 00:01:02: ... :3f %*phC 00:01:02: ... :3f
......
...@@ -1155,6 +1155,30 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr, ...@@ -1155,6 +1155,30 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
return number(buf, end, *(const netdev_features_t *)addr, spec); return number(buf, end, *(const netdev_features_t *)addr, spec);
} }
static noinline_for_stack
char *address_val(char *buf, char *end, const void *addr,
struct printf_spec spec, const char *fmt)
{
unsigned long long num;
spec.flags |= SPECIAL | SMALL | ZEROPAD;
spec.base = 16;
switch (fmt[1]) {
case 'd':
num = *(const dma_addr_t *)addr;
spec.field_width = sizeof(dma_addr_t) * 2 + 2;
break;
case 'p':
default:
num = *(const phys_addr_t *)addr;
spec.field_width = sizeof(phys_addr_t) * 2 + 2;
break;
}
return number(buf, end, num, spec);
}
int kptr_restrict __read_mostly; int kptr_restrict __read_mostly;
/* /*
...@@ -1218,7 +1242,8 @@ int kptr_restrict __read_mostly; ...@@ -1218,7 +1242,8 @@ int kptr_restrict __read_mostly;
* N no separator * N no separator
* The maximum supported length is 64 bytes of the input. Consider * The maximum supported length is 64 bytes of the input. Consider
* to use print_hex_dump() for the larger input. * to use print_hex_dump() for the larger input.
* - 'a' For a phys_addr_t type and its derivative types (passed by reference) * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
* (default assumed to be phys_addr_t, passed by reference)
* - 'd[234]' For a dentry name (optionally 2-4 last components) * - 'd[234]' For a dentry name (optionally 2-4 last components)
* - 'D[234]' Same as 'd' but for a struct file * - 'D[234]' Same as 'd' but for a struct file
* *
...@@ -1353,11 +1378,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, ...@@ -1353,11 +1378,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
} }
break; break;
case 'a': case 'a':
spec.flags |= SPECIAL | SMALL | ZEROPAD; return address_val(buf, end, ptr, spec, fmt);
spec.field_width = sizeof(phys_addr_t) * 2 + 2;
spec.base = 16;
return number(buf, end,
(unsigned long long) *((phys_addr_t *)ptr), spec);
case 'd': case 'd':
return dentry_name(buf, end, ptr, spec, fmt); return dentry_name(buf, end, ptr, spec, fmt);
case 'D': case 'D':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment