Skip to contentSkip to conversation

power: supply: sysfs: Remove duplicate NUL termination

PATCH Applied Kees Cook 2 participants 2 messages Apr 16, 2025 – Apr 27, 2025 Power supply

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 power: supply: sysfs: Remove duplicate NUL termination

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).

---
Cc: Sebastian Reichel <[email protected]>
Cc: <[email protected]>

---
 drivers/power/supply/power_supply_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_sysfs.c +1 -1
index edb058c19c9c..439dd0bf8644 100644
@@ -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,		\
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Kees Cook

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'

Quoted 4 lines
  183 |         POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
      |         ^~~~~~~~~~~~~~~~~

[...]

Applied, thanks!

[1/1] power: supply: sysfs: Remove duplicate NUL termination

      commit: 77f5bb150132bbbcd6bc37ffdc80c9e140e373a4

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>