Skip to content

Commit 23199d2

Browse files
kaushlenshuahkh
authored andcommitted
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>
1 parent 57b100d commit 23199d2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tools/power/cpupower/lib/cpuidle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ int cpuidle_state_disable(unsigned int cpu,
233233
{
234234
char value[SYSFS_PATH_MAX];
235235
int bytes_written;
236+
int len;
236237

237238
if (cpuidle_state_count(cpu) <= idlestate)
238239
return -1;
@@ -241,10 +242,10 @@ int cpuidle_state_disable(unsigned int cpu,
241242
idlestate_value_files[IDLESTATE_DISABLE]))
242243
return -2;
243244

244-
snprintf(value, SYSFS_PATH_MAX, "%u", disable);
245+
len = snprintf(value, SYSFS_PATH_MAX, "%u", disable);
245246

246247
bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable",
247-
value, sizeof(disable));
248+
value, len);
248249
if (bytes_written)
249250
return 0;
250251
return -3;

0 commit comments

Comments
 (0)