Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/cpupower: Fix incorrect size in cpuidle_state_disable()

Fix incorrect size parameter passed to cpuidle_state_write_file() in
cpuidle_state_disable().

The function was incorrectly using sizeof(disable) which returns the
size of the unsigned int variable (4 bytes) instead of the actual
length of the string stored in the 'value' buffer.

Since 'value' is populated with snprintf() to contain the string
representation of the disable value, we should use the length
returned by snprintf() to get the correct string length for
writing to the sysfs file.

This ensures the correct number of bytes is written to the cpuidle
state disable file in sysfs.

Link: https://lore.kernel.org/r/20250917050820.1785377-1-kaushlendra.kumar@intel.com
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Kaushlendra Kumar and committed by
Shuah Khan
23199d2a 57b100d4

+3 -2
+3 -2
tools/power/cpupower/lib/cpuidle.c
··· 233 233 { 234 234 char value[SYSFS_PATH_MAX]; 235 235 int bytes_written; 236 + int len; 236 237 237 238 if (cpuidle_state_count(cpu) <= idlestate) 238 239 return -1; ··· 242 241 idlestate_value_files[IDLESTATE_DISABLE])) 243 242 return -2; 244 243 245 - snprintf(value, SYSFS_PATH_MAX, "%u", disable); 244 + len = snprintf(value, SYSFS_PATH_MAX, "%u", disable); 246 245 247 246 bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable", 248 - value, sizeof(disable)); 247 + value, len); 249 248 if (bytes_written) 250 249 return 0; 251 250 return -3;