lib/tests/printf_kunit.c:740:49: sparse: sparse: cast from restricted gfp_t

From: kernel test robot

Date: Mon Mar 02 2026 - 03:10:45 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 11439c4635edd669ae435eec308f4ab8a0804808
commit: 7a79e7daa84e230266184a2018507551086c2317 printf: convert self-test to KUnit
date: 12 months ago
config: sparc64-randconfig-r132-20260302 (https://download.01.org/0day-ci/archive/20260302/202603021615.d6FkL331-lkp@xxxxxxxxx/config)
compiler: sparc64-linux-gcc (GCC) 8.5.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260302/202603021615.d6FkL331-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603021615.d6FkL331-lkp@xxxxxxxxx/

sparse warnings: (new ones prefixed by >>)
>> lib/tests/printf_kunit.c:740:49: sparse: sparse: cast from restricted gfp_t
lib/tests/printf_kunit.c:744:58: sparse: sparse: cast from restricted gfp_t

vim +740 lib/tests/printf_kunit.c

c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 702
7a79e7daa84e23 lib/tests/printf_kunit.c Tamir Duberstein 2025-03-07 703 static void
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 704 flags(void)
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 705 {
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 706 unsigned long flags;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 707 char *cmp_buffer;
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 708 gfp_t gfp;
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 709
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 710 cmp_buffer = kmalloc(BUF_SIZE, GFP_KERNEL);
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 711 if (!cmp_buffer)
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 712 return;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 713
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 714 flags = 0;
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 715 page_flags_test(0, 0, 0, 0, 0, flags, "", cmp_buffer);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 716
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 717 flags = 1UL << NR_PAGEFLAGS;
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 718 page_flags_test(0, 0, 0, 0, 0, flags, "", cmp_buffer);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 719
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 720 flags |= 1UL << PG_uptodate | 1UL << PG_dirty | 1UL << PG_lru
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 721 | 1UL << PG_active | 1UL << PG_swapbacked;
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 722 page_flags_test(1, 1, 1, 0x1fffff, 1, flags,
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 723 "uptodate|dirty|lru|active|swapbacked",
c244297acbe51f lib/test_printf.c Yafang Shao 2021-03-19 724 cmp_buffer);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 725
8d0920bde5eb8e lib/test_printf.c David Hildenbrand 2021-04-22 726 flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
8d0920bde5eb8e lib/test_printf.c David Hildenbrand 2021-04-22 727 test("read|exec|mayread|maywrite|mayexec", "%pGv", &flags);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 728
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 729 gfp = GFP_TRANSHUGE;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 730 test("GFP_TRANSHUGE", "%pGg", &gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 731
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 732 gfp = GFP_ATOMIC|__GFP_DMA;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 733 test("GFP_ATOMIC|GFP_DMA", "%pGg", &gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 734
2973d8229b78d3 lib/test_printf.c NeilBrown 2023-01-13 735 gfp = __GFP_HIGH;
2973d8229b78d3 lib/test_printf.c NeilBrown 2023-01-13 736 test("__GFP_HIGH", "%pGg", &gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 737
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 738 /* Any flags not translated by the table should remain numeric */
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 739 gfp = ~__GFP_BITS_MASK;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 @740 snprintf(cmp_buffer, BUF_SIZE, "%#lx", (unsigned long) gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 741 test(cmp_buffer, "%pGg", &gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 742
2973d8229b78d3 lib/test_printf.c NeilBrown 2023-01-13 743 snprintf(cmp_buffer, BUF_SIZE, "__GFP_HIGH|%#lx",
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 744 (unsigned long) gfp);
2973d8229b78d3 lib/test_printf.c NeilBrown 2023-01-13 745 gfp |= __GFP_HIGH;
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 746 test(cmp_buffer, "%pGg", &gfp);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 747
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 748 kfree(cmp_buffer);
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 749 }
edf14cdbf9a0e5 lib/test_printf.c Vlastimil Babka 2016-03-15 750

:::::: The code at line 740 was first introduced by commit
:::::: edf14cdbf9a0e5ab52698ca66d07a76ade0d5c46 mm, printk: introduce new format string for flags

:::::: TO: Vlastimil Babka <vbabka@xxxxxxx>
:::::: CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki