summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/test_printf.c61
-rw-r--r--lib/vsprintf.c11
2 files changed, 35 insertions, 37 deletions
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 55082432f37e..07309c45f327 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -586,70 +586,59 @@ struct page_flags_test {
int width;
int shift;
int mask;
- unsigned long value;
const char *fmt;
const char *name;
};
-static struct page_flags_test pft[] = {
+static const struct page_flags_test pft[] = {
{SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK,
- 0, "%d", "section"},
+ "%d", "section"},
{NODES_WIDTH, NODES_PGSHIFT, NODES_MASK,
- 0, "%d", "node"},
+ "%d", "node"},
{ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK,
- 0, "%d", "zone"},
+ "%d", "zone"},
{LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK,
- 0, "%#x", "lastcpupid"},
+ "%#x", "lastcpupid"},
{KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK,
- 0, "%#x", "kasantag"},
+ "%#x", "kasantag"},
};
static void __init
page_flags_test(int section, int node, int zone, int last_cpupid,
- int kasan_tag, int flags, const char *name, char *cmp_buf)
+ int kasan_tag, unsigned long flags, const char *name,
+ char *cmp_buf)
{
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
- unsigned long page_flags = 0;
- unsigned long size = 0;
+ unsigned long size;
bool append = false;
int i;
- flags &= PAGEFLAGS_MASK;
- if (flags) {
- page_flags |= flags;
- snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
- size = strlen(cmp_buf);
-#if SECTIONS_WIDTH || NODES_WIDTH || ZONES_WIDTH || \
- LAST_CPUPID_WIDTH || KASAN_TAG_WIDTH
- /* Other information also included in page flags */
- snprintf(cmp_buf + size, BUF_SIZE - size, "|");
- size = strlen(cmp_buf);
-#endif
- }
+ for (i = 0; i < ARRAY_SIZE(values); i++)
+ flags |= (values[i] & pft[i].mask) << pft[i].shift;
- /* Set the test value */
- for (i = 0; i < ARRAY_SIZE(pft); i++)
- pft[i].value = values[i];
+ size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
+ if (flags & PAGEFLAGS_MASK) {
+ size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
+ append = true;
+ }
for (i = 0; i < ARRAY_SIZE(pft); i++) {
if (!pft[i].width)
continue;
- if (append) {
- snprintf(cmp_buf + size, BUF_SIZE - size, "|");
- size = strlen(cmp_buf);
- }
+ if (append)
+ size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
- page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift;
- snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name);
- size = strlen(cmp_buf);
- snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
- pft[i].value & pft[i].mask);
- size = strlen(cmp_buf);
+ size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
+ pft[i].name);
+ size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
+ values[i] & pft[i].mask);
append = true;
}
- test(cmp_buf, "%pGp", &page_flags);
+ snprintf(cmp_buf + size, BUF_SIZE - size, ")");
+
+ test(cmp_buf, "%pGp", &flags);
}
static void __init
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7ad44f2c8f5..f90f91d83920 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -408,8 +408,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
+static_assert(SIGN == 1);
static_assert(ZEROPAD == ('0' - ' '));
-static_assert(SMALL == ' ');
+static_assert(SMALL == ('a' ^ 'A'));
enum format_type {
FORMAT_TYPE_NONE, /* Just a string part */
@@ -2023,6 +2024,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
bool append = false;
int i;
+ buf = number(buf, end, flags, default_flag_spec);
+ if (buf < end)
+ *buf = '(';
+ buf++;
+
/* Page flags from the main area. */
if (main_flags) {
buf = format_flags(buf, end, main_flags, pageflag_names);
@@ -2051,6 +2057,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
append = true;
}
+ if (buf < end)
+ *buf = ')';
+ buf++;
return buf;
}