Re: [PATCH] arch/x86: Fix the wrong format specifier

From: kernel test robot
Date: Wed Dec 04 2024 - 16:23:39 EST


Hi liujing,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tip/master]
[also build test WARNING on tip/x86/core tip/auto-latest linus/master v6.13-rc1 next-20241204]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/liujing/arch-x86-Fix-the-wrong-format-specifier/20241204-225811
base: tip/master
patch link: https://lore.kernel.org/r/20241204143322.7772-1-liujing%40cmss.chinamobile.com
patch subject: [PATCH] arch/x86: Fix the wrong format specifier
config: x86_64-buildonly-randconfig-006-20241205 (https://download.01.org/0day-ci/archive/20241205/202412050541.CvNgnYXM-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/20241205/202412050541.CvNgnYXM-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/202412050541.CvNgnYXM-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

arch/x86/kernel/hpet.c: In function 'hpet_late_init':
>> arch/x86/kernel/hpet.c:731:40: warning: '%u' directive writing between 1 and 10 bytes into a region of size 6 [-Wformat-overflow=]
731 | sprintf(hc->name, "hpet%u", i);
| ^~
In function 'hpet_select_clockevents',
inlined from 'hpet_late_init' at arch/x86/kernel/hpet.c:1146:2:
arch/x86/kernel/hpet.c:731:35: note: directive argument in the range [0, 4294967294]
731 | sprintf(hc->name, "hpet%u", i);
| ^~~~~~~~
arch/x86/kernel/hpet.c:731:17: note: 'sprintf' output between 6 and 15 bytes into a destination of size 10
731 | sprintf(hc->name, "hpet%u", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +731 arch/x86/kernel/hpet.c

703
704 static void __init hpet_select_clockevents(void)
705 {
706 unsigned int i;
707
708 hpet_base.nr_clockevents = 0;
709
710 /* No point if MSI is disabled or CPU has an Always Running APIC Timer */
711 if (hpet_msi_disable || boot_cpu_has(X86_FEATURE_ARAT))
712 return;
713
714 hpet_print_config();
715
716 hpet_domain = hpet_create_irq_domain(hpet_blockid);
717 if (!hpet_domain)
718 return;
719
720 for (i = 0; i < hpet_base.nr_channels; i++) {
721 struct hpet_channel *hc = hpet_base.channels + i;
722 int irq;
723
724 if (hc->mode != HPET_MODE_UNUSED)
725 continue;
726
727 /* Only consider HPET channel with MSI support */
728 if (!(hc->boot_cfg & HPET_TN_FSB_CAP))
729 continue;
730
> 731 sprintf(hc->name, "hpet%u", i);
732
733 irq = hpet_assign_irq(hpet_domain, hc, hc->num);
734 if (irq <= 0)
735 continue;
736
737 hc->irq = irq;
738 hc->mode = HPET_MODE_CLOCKEVT;
739
740 if (++hpet_base.nr_clockevents == num_possible_cpus())
741 break;
742 }
743
744 pr_info("%d channels of %d reserved for per-cpu timers\n",
745 hpet_base.nr_channels, hpet_base.nr_clockevents);
746 }
747

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