Re: [akpm-mm:mm-unstable 61/88] mm/cma_debug.c:189:55: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 30, 2025 at 7:13 PM kernel test robot <lkp@xxxxxxxxx> wrote:
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> head:   495206a68b359eb6117d0860861578113bbb94e7
> commit: 77cbd63e91fa6c5f6157a30e61a380b6c47c1443 [61/88] mm, cma: support multiple contiguous ranges, if requested
> config: x86_64-buildonly-randconfig-003-20250131 (https://download.01.org/0day-ci/archive/20250131/202501311125.wbG1DN2B-lkp@xxxxxxxxx/config)
> compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250131/202501311125.wbG1DN2B-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/202501311125.wbG1DN2B-lkp@xxxxxxxxx/
>
> All warnings (new ones prefixed by >>):
>
>    mm/cma_debug.c: In function 'cma_debugfs_add_one':
> >> mm/cma_debug.c:189:55: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
>      189 |                 snprintf(rdirname, sizeof(rdirname), "%d", r);
>          |                                                       ^~
>    mm/cma_debug.c:189:54: note: directive argument in the range [-2147483644, 2147483646]
>      189 |                 snprintf(rdirname, sizeof(rdirname), "%d", r);
>          |                                                      ^~~~
>    mm/cma_debug.c:189:17: note: 'snprintf' output between 2 and 12 bytes into a destination of size 3
>      189 |                 snprintf(rdirname, sizeof(rdirname), "%d", r);
>          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> vim +189 mm/cma_debug.c
>
>    168
>    169  static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
>    170  {
>    171          struct dentry *tmp, *dir, *rangedir;
>    172          int r;
>    173          char rdirname[3];
>    174          struct cma_memrange *cmr;
>    175
>    176          tmp = debugfs_create_dir(cma->name, root_dentry);
>    177
>    178          debugfs_create_file("alloc", 0200, tmp, cma, &cma_alloc_fops);
>    179          debugfs_create_file("free", 0200, tmp, cma, &cma_free_fops);
>    180          debugfs_create_file("count", 0444, tmp, &cma->count, &cma_debugfs_fops);
>    181          debugfs_create_file("order_per_bit", 0444, tmp,
>    182                              &cma->order_per_bit, &cma_debugfs_fops);
>    183          debugfs_create_file("used", 0444, tmp, cma, &cma_used_fops);
>    184          debugfs_create_file("maxchunk", 0444, tmp, cma, &cma_maxchunk_fops);
>    185
>    186          rangedir = debugfs_create_dir("ranges", tmp);
>    187          for (r = 0; r < cma->nranges; r++) {
>    188                  cmr = &cma->ranges[r];
>  > 189                  snprintf(rdirname, sizeof(rdirname), "%d", r);
>    190                  dir = debugfs_create_dir(rdirname, rangedir);
>    191                  debugfs_create_file("base_pfn", 0444, dir,
>    192                              &cmr->base_pfn, &cma_debugfs_fops);
>    193                  cmr->dfs_bitmap.array = (u32 *)cmr->bitmap;
>    194                  cmr->dfs_bitmap.n_elements =
>    195                          DIV_ROUND_UP(cma_bitmap_maxno(cma, cmr),
>    196                                          BITS_PER_BYTE * sizeof(u32));
>    197                  debugfs_create_u32_array("bitmap", 0444, dir,
>    198                                  &cmr->dfs_bitmap);
>    199          }
>    200
>    201          /*
>    202           * Backward compatible symlinks to range 0 for base_pfn and bitmap.
>    203           */
>    204          debugfs_create_symlink("base_pfn", tmp, "ranges/0/base_pfn");
>    205          debugfs_create_symlink("bitmap", tmp, "ranges/0/bitmap");
>    206  }
>    207
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

CMA_MAX_RANGES is 8, and it's an snprintf, so no, it will never use
more than 1 digit. But, I can bump up the size of the buffer is that
makes the compiler happier in this case. I'll do that.


- Frank





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux