drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]
243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
| ^1 warning generated.
vim +/snprintf +243 drivers/platform/surface/surface3_power.c
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 207
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 208 static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix)
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 209 {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 210 struct i2c_client *client = cdata->bat0;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 211 char buf[SURFACE_3_STRLEN];
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 212 int ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 213
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 214 *bix = default_bix;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 215
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 216 /* get design capacity */
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 217 ret = i2c_smbus_read_word_data(client,
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 218 MSHW0011_BAT0_REG_DESIGN_CAPACITY);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 219 if (ret < 0) {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 220 dev_err(&client->dev, "Error reading design capacity: %d\n",
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 221 ret);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 222 return ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 223 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 224 bix->design_capacity = ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 225
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 226 /* get last full charge capacity */
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 227 ret = i2c_smbus_read_word_data(client,
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 228 MSHW0011_BAT0_REG_FULL_CHG_CAPACITY);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 229 if (ret < 0) {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 230 dev_err(&client->dev,
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 231 "Error reading last full charge capacity: %d\n", ret);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 232 return ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 233 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 234 bix->last_full_charg_capacity = ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 235
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 236 /* get serial number */
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 237 ret = i2c_smbus_read_i2c_block_data(client, MSHW0011_BAT0_REG_SERIAL_NO,
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 238 sizeof(buf), buf);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 239 if (ret != sizeof(buf)) {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 240 dev_err(&client->dev, "Error reading serial no: %d\n", ret);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 241 return ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 242 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 @243 snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 244
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 245 /* get cycle count */
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 246 ret = i2c_smbus_read_word_data(client, MSHW0011_BAT0_REG_CYCLE_CNT);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 247 if (ret < 0) {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 248 dev_err(&client->dev, "Error reading cycle count: %d\n", ret);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 249 return ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 250 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 251 bix->cycle_count = ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 252
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 253 /* get OEM name */
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 254 ret = i2c_smbus_read_i2c_block_data(client, MSHW0011_BAT0_REG_OEM,
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 255 4, buf);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 256 if (ret != 4) {
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 257 dev_err(&client->dev, "Error reading cycle count: %d\n", ret);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 258 return ret;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 259 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 260 snprintf(bix->OEM, ARRAY_SIZE(bix->OEM), "%3pE", buf);
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 261
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 262 return 0;
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 263 }
b1f81b496b0d14 drivers/platform/x86/surface3_power.c Blaž Hrastnik 2020-03-21 264 :::::: The code at line 243 was first introduced by commit
:::::: b1f81b496b0d14382a9cf160cc4dbdefb233f936 platform/x86: surface3_power: MSHW0011 rev-eng implementation
:::::: TO: Blaž Hrastnik <[email protected]>
:::::: CC: Andy Shevchenko <[email protected]>
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 14 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on make W=1 builds which is also annoying to people what want have that clean.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 26 lines · Andy Shevchenko
Quoted 13 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.
Quoted 6 lines
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on
make W=1builds which is also annoying to people who want to have that clean.
Actually using %pE implies that the buffer should be 4 times bigger than the input string. So, with the given format string the ARRAY_SIZE(bix->serial) has to be equal to or greater than 3 * 4 + 6 * 4 + 1, i.e. 37.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 35 lines · Andy Shevchenko
Quoted 26 lines · Andy Shevchenko
Quoted 13 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.Quoted 6 lines
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on
make W=1builds which is also annoying to people who want to have that clean.
Quoted 4 lines
Actually using %pE implies that the buffer should be 4 times bigger than the input string. So, with the given format string the
ARRAY_SIZE(bix->serial)has to be equal to or greater than 3 * 4 + 6 * 4 + 1, i.e. 37.
#define SURFACE_3_STRLEN 10
struct bix {
...
char serial[SURFACE_3_STRLEN];Oops...
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 41 lines · Geert Uytterhoeven
Quoted 35 lines · Andy Shevchenko
Quoted 26 lines · Andy Shevchenko
Quoted 13 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.Quoted 6 lines
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on
make W=1builds which is also annoying to people who want to have that clean.Quoted 4 lines
Actually using %pE implies that the buffer should be 4 times bigger than the input string. So, with the given format string the
ARRAY_SIZE(bix->serial)has to be equal to or greater than 3 * 4 + 6 * 4 + 1, i.e. 37.
Quoted 7 lines
#define SURFACE_3_STRLEN 10 struct bix { ... char serial[SURFACE_3_STRLEN];Oops...
It works because IRL we haven't seen the broken strings that %pE escapes with help of an octal code. But if one doesn't trust that input and uses %pE they should provide enough buffer for that translation to happen.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nathan Chancellor
maintainerQuoted 26 lines · Andy Shevchenko
Quoted 14 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.
Quoted 6 lines
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on
make W=1builds which is also annoying to people what want have that clean.
Hmmm, I missed that -Wformat-truncation-non-kprintf was only disabled in the non-W=1 block in scripts/Makefile.extrawarn. We never want to see these warnings at any level because they will almost always be a false positive, that's why the "non-kprintf" flags even exist in the first place:
https://github.com/llvm/llvm-project/pull/65969
I suspect we want something like this.
scripts/Makefile.extrawarn +5 -5
@@ -31,6 +31,11 @@ KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds ifdef CONFIG_CC_IS_CLANG # The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable. KBUILD_CFLAGS += -Wno-gnu + +# Clang checks for overflow/truncation with '%p', while GCC does not: +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219 +KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf) +KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf) else # gcc inanely warns about local variables called 'main'
@@ -102,11 +107,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -else -# Clang checks for overflow/truncation with '%p', while GCC does not: -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219 -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf) endif KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
Quoted 34 lines · On Wed, 29 Jan 2025 06:46:48 -0700 Nathan Chancellor <[email protected]> wrote:
Quoted 26 lines · Andy Shevchenko
Quoted 14 lines · kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface date: 4 years, 3 months ago config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Quoted 4 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]243 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this formatting string...
Quoted 2 lines
| ^
1 warning generated.Quoted 6 lines
I do not know how to properly address this because it's false positive due to the compiler not being aware of pointer extensions used in Linux kernel. The w/a is to increase the buffer if we can, but is it practical? OTOH, this warning will be translated to a compilation error in case of default WERROR settings on
make W=1builds which is also annoying to people what want have that clean.
Quoted 5 lines
Hmmm, I missed that -Wformat-truncation-non-kprintf was only disabled in the non-W=1 block in
scripts/Makefile.extrawarn. We never want to see these warnings at any level because they will almost always be a false positive, that's why the "non-kprintf" flags even exist in the first place:
...
There is a separate issue that it doesn't seem to be easy to mark a specific snprintf() as one that will not actually overflow or where truncation is fine.
Persuading the compiler that the buffer size isn't constant currently works, but I expect the compiler will start double checking against ARRAY_SIZE(buffer) 'any time soon' which will require the same treatment applied to the buffer address.
David