sfc: avoid truncating MCDI hwmon attribute names
Subsystems (3)
PATCH 1/1 sfc: avoid truncating MCDI hwmon attribute names
The name of each MCDI hwmon attribute is built in a 12-byte buffer as prefix + 1-based per-type index + suffix, with prefixes up to "power" and suffixes up to "_input". With W=1 gcc reports:
warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
at mcdi_mon.c:457, :488 and :495, in both the sfc and the siena copy.
The same 12-byte field in struct efx_mcdi_mon_attribute, which receives a strscpy() of the local buffer and backs the sysfs attribute name, would also truncate silently once a sensor type has more than 9
instances: "power10_crit" already needs 13 bytes.
Enlarge both buffers to 24 bytes, enough for the longest possible name:
"power" + 10 digits + "_input" + NUL = 22 bytes.
--- drivers/net/ethernet/sfc/mcdi_mon.c | 4 ++-- drivers/net/ethernet/sfc/siena/mcdi_mon.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/sfc/mcdi_mon.c +2 -2
@@ -138,7 +138,7 @@ struct efx_mcdi_mon_attribute {unsigned int type;enum efx_hwmon_type hwmon_type;unsigned int limit_value; -char name[12 ]; +char name[24 ]; };static int efx_mcdi_mon_update (struct efx_nic *efx)
@@ -308,7 +308,7 @@ int efx_mcdi_mon_probe(struct efx_nic *efx)MCDI_DECLARE_BUF (outbuf,MC_CMD_SENSOR_INFO_OUT_LENMAX );unsigned int n_pages, n_sensors, n_attrs, page;size_t outlen; -char name[12 ]; +char name[24 ];u32 mask;int rc, i, j, type;
drivers/net/ethernet/sfc/siena/mcdi_mon.c +2 -2
@@ -138,7 +138,7 @@ struct efx_mcdi_mon_attribute {unsigned int type;enum efx_hwmon_type hwmon_type;unsigned int limit_value; -char name[12 ]; +char name[24 ]; };static int efx_mcdi_mon_update (struct efx_nic *efx)
@@ -308,7 +308,7 @@ int efx_siena_mcdi_mon_probe(struct efx_nic *efx)MCDI_DECLARE_BUF (outbuf,MC_CMD_SENSOR_INFO_OUT_LENMAX );unsigned int n_pages, n_sensors, n_attrs, page;size_t outlen; -char name[12 ]; +char name[24 ];u32 mask;int rc, i, j, type;
Signature · 1 line
2.43.0
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 5 Nov 2026 10:01:15 +0800 you wrote:
The name of each MCDI hwmon attribute is built in a 12-byte buffer as prefix + 1-based per-type index + suffix, with prefixes up to "power" and suffixes up to "
_input". With W=1 gcc reports:warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
[...]
Here is the summary with links:
- [net-next] sfc: avoid truncating MCDI hwmon attribute names
https://git.kernel.org/netdev/net-next/c/97ced2c090bf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html