Message ID | 20211012182647.1605095-2-willy@infradead.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Improvements to %pGp | expand |
On Wed, Oct 13, 2021 at 2:29 AM Matthew Wilcox (Oracle) <willy@infradead.org> wrote: > > Instead of assigning ptf[i].value, leave the values in the on-stack > array and then we can make the array const. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Yafang Shao <laoar.shao@gmail.com> > --- > lib/test_printf.c | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > > diff --git a/lib/test_printf.c b/lib/test_printf.c > index 55082432f37e..a52c1c3a55ba 100644 > --- a/lib/test_printf.c > +++ b/lib/test_printf.c > @@ -586,22 +586,21 @@ 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 > @@ -627,10 +626,6 @@ page_flags_test(int section, int node, int zone, int last_cpupid, > #endif > } > > - /* Set the test value */ > - for (i = 0; i < ARRAY_SIZE(pft); i++) > - pft[i].value = values[i]; > - > for (i = 0; i < ARRAY_SIZE(pft); i++) { > if (!pft[i].width) > continue; > @@ -640,11 +635,11 @@ page_flags_test(int section, int node, int zone, int last_cpupid, > size = strlen(cmp_buf); > } > > - page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift; > + page_flags |= (values[i] & 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); > + values[i] & pft[i].mask); > size = strlen(cmp_buf); > append = true; > } > -- > 2.32.0 >
On Tue 2021-10-12 19:26:43, Matthew Wilcox (Oracle) wrote: > Instead of assigning ptf[i].value, leave the values in the on-stack > array and then we can make the array const. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Best Regards, Petr
On 10/12/21 11:56 PM, Matthew Wilcox (Oracle) wrote: > Instead of assigning ptf[i].value, leave the values in the on-stack > array and then we can make the array const. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> > --- > lib/test_printf.c | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > > diff --git a/lib/test_printf.c b/lib/test_printf.c > index 55082432f37e..a52c1c3a55ba 100644 > --- a/lib/test_printf.c > +++ b/lib/test_printf.c > @@ -586,22 +586,21 @@ 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 > @@ -627,10 +626,6 @@ page_flags_test(int section, int node, int zone, int last_cpupid, > #endif > } > > - /* Set the test value */ > - for (i = 0; i < ARRAY_SIZE(pft); i++) > - pft[i].value = values[i]; > - > for (i = 0; i < ARRAY_SIZE(pft); i++) { > if (!pft[i].width) > continue; > @@ -640,11 +635,11 @@ page_flags_test(int section, int node, int zone, int last_cpupid, > size = strlen(cmp_buf); > } > > - page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift; > + page_flags |= (values[i] & 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); > + values[i] & pft[i].mask); > size = strlen(cmp_buf); > append = true; > } > Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
diff --git a/lib/test_printf.c b/lib/test_printf.c index 55082432f37e..a52c1c3a55ba 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -586,22 +586,21 @@ 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 @@ -627,10 +626,6 @@ page_flags_test(int section, int node, int zone, int last_cpupid, #endif } - /* Set the test value */ - for (i = 0; i < ARRAY_SIZE(pft); i++) - pft[i].value = values[i]; - for (i = 0; i < ARRAY_SIZE(pft); i++) { if (!pft[i].width) continue; @@ -640,11 +635,11 @@ page_flags_test(int section, int node, int zone, int last_cpupid, size = strlen(cmp_buf); } - page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift; + page_flags |= (values[i] & 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); + values[i] & pft[i].mask); size = strlen(cmp_buf); append = true; }
Instead of assigning ptf[i].value, leave the values in the on-stack array and then we can make the array const. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- lib/test_printf.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)