1 From 77f5bb150132bbbcd6bc37ffdc80c9e140e373a4 Mon Sep 17 00:00:00 2001
2 From: Kees Cook <kees@kernel.org>
3 Date: Wed, 16 Apr 2025 15:27:41 -0700
4 Subject: [PATCH] power: supply: sysfs: Remove duplicate NUL termination
6 GCC 15's new -Wunterminated-string-initialization notices that one of
7 the sysfs attr strings would lack the implicit trailing NUL byte during
10 drivers/power/supply/power_supply_sysfs.c:183:57: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (32 chars into 31 available) [-Wunterminated-string-initialization]
11 183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
13 drivers/power/supply/power_supply_sysfs.c:36:23: note: in definition of macro '_POWER_SUPPLY_ATTR'
14 36 | .attr_name = #_name "\0", \
16 drivers/power/supply/power_supply_sysfs.c:183:9: note: in expansion of macro 'POWER_SUPPLY_ATTR'
17 183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
20 However, the macro used was explicitly adding a trailing NUL byte (which
21 is not needed). Remove this to avoid the GCC warning. No binary
22 differences are seen after this change (there was always run for a NUL
23 byte, it's just that the _second_ NUL byte was getting truncated).
25 Signed-off-by: Kees Cook <kees@kernel.org>
26 Link: https://lore.kernel.org/r/20250416222740.work.569-kees@kernel.org
27 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
29 --- a/drivers/power/supply/power_supply_sysfs.c
30 +++ b/drivers/power/supply/power_supply_sysfs.c
31 @@ -32,7 +32,7 @@ struct power_supply_attr {
32 [POWER_SUPPLY_PROP_ ## _name] = \
34 .prop_name = #_name, \
35 - .attr_name = #_name "\0", \
36 + .attr_name = #_name, \
37 .text_values = _text, \
38 .text_values_len = _len, \