* [PATCH] power: supply: sysfs: Remove duplicate NUL termination
@ 2025-04-16 22:27 Kees Cook
2025-04-27 23:27 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2025-04-16 22:27 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: Kees Cook, linux-pm, linux-kernel, linux-hardening
GCC 15's new -Wunterminated-string-initialization notices that one of
the sysfs attr strings would lack the implicit trailing NUL byte during
initialization:
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]
183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
| ^
drivers/power/supply/power_supply_sysfs.c:36:23: note: in definition of macro '_POWER_SUPPLY_ATTR'
36 | .attr_name = #_name "\0", \
| ^~~~~
drivers/power/supply/power_supply_sysfs.c:183:9: note: in expansion of macro 'POWER_SUPPLY_ATTR'
183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
| ^~~~~~~~~~~~~~~~~
However, the macro used was explicitly adding a trailing NUL byte (which
is not needed). Remove this to avoid the GCC warning. No binary
differences are seen after this change (there was always run for a NUL
byte, it's just that the _second_ NUL byte was getting truncated).
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Sebastian Reichel <sre@kernel.org>
Cc: <linux-pm@vger.kernel.org>
---
drivers/power/supply/power_supply_sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index edb058c19c9c..439dd0bf8644 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -33,7 +33,7 @@ struct power_supply_attr {
[POWER_SUPPLY_PROP_ ## _name] = \
{ \
.prop_name = #_name, \
- .attr_name = #_name "\0", \
+ .attr_name = #_name, \
.text_values = _text, \
.text_values_len = _len, \
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: sysfs: Remove duplicate NUL termination
2025-04-16 22:27 [PATCH] power: supply: sysfs: Remove duplicate NUL termination Kees Cook
@ 2025-04-27 23:27 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2025-04-27 23:27 UTC (permalink / raw)
To: Sebastian Reichel, Kees Cook; +Cc: linux-pm, linux-kernel, linux-hardening
On Wed, 16 Apr 2025 15:27:41 -0700, Kees Cook wrote:
> GCC 15's new -Wunterminated-string-initialization notices that one of
> the sysfs attr strings would lack the implicit trailing NUL byte during
> initialization:
>
> 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]
> 183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
> | ^
> drivers/power/supply/power_supply_sysfs.c:36:23: note: in definition of macro '_POWER_SUPPLY_ATTR'
> 36 | .attr_name = #_name "\0", \
> | ^~~~~
> drivers/power/supply/power_supply_sysfs.c:183:9: note: in expansion of macro 'POWER_SUPPLY_ATTR'
> 183 | POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
> | ^~~~~~~~~~~~~~~~~
>
> [...]
Applied, thanks!
[1/1] power: supply: sysfs: Remove duplicate NUL termination
commit: 77f5bb150132bbbcd6bc37ffdc80c9e140e373a4
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-27 23:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 22:27 [PATCH] power: supply: sysfs: Remove duplicate NUL termination Kees Cook
2025-04-27 23:27 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).