* [PATCH v2] tools/cpupower: Fix incorrect size in cpuidle_state_disable()
@ 2025-09-17 5:08 Kaushlendra Kumar
2025-09-25 20:22 ` Shuah Khan
0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-09-17 5:08 UTC (permalink / raw)
To: shuah, trenn, jwyatt; +Cc: linux-pm, Kaushlendra Kumar
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.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
Changes in v2:
- Use snprintf() return value instead of strlen() for better efficiency
tools/power/cpupower/lib/cpuidle.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/power/cpupower/lib/cpuidle.c b/tools/power/cpupower/lib/cpuidle.c
index 0ecac009273c..f2c1139adf71 100644
--- a/tools/power/cpupower/lib/cpuidle.c
+++ b/tools/power/cpupower/lib/cpuidle.c
@@ -233,6 +233,7 @@ int cpuidle_state_disable(unsigned int cpu,
{
char value[SYSFS_PATH_MAX];
int bytes_written;
+ int len;
if (cpuidle_state_count(cpu) <= idlestate)
return -1;
@@ -241,10 +242,10 @@ int cpuidle_state_disable(unsigned int cpu,
idlestate_value_files[IDLESTATE_DISABLE]))
return -2;
- snprintf(value, SYSFS_PATH_MAX, "%u", disable);
+ len = snprintf(value, SYSFS_PATH_MAX, "%u", disable);
bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable",
- value, sizeof(disable));
+ value, len);
if (bytes_written)
return 0;
return -3;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] tools/cpupower: Fix incorrect size in cpuidle_state_disable()
2025-09-17 5:08 [PATCH v2] tools/cpupower: Fix incorrect size in cpuidle_state_disable() Kaushlendra Kumar
@ 2025-09-25 20:22 ` Shuah Khan
0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2025-09-25 20:22 UTC (permalink / raw)
To: Kaushlendra Kumar, shuah, trenn, jwyatt; +Cc: linux-pm, Shuah Khan
On 9/16/25 23:08, Kaushlendra Kumar wrote:
> 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.
>
> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
> ---
> Changes in v2:
> - Use snprintf() return value instead of strlen() for better efficiency
>
Thank you. Applied to git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/log/?h=cpupower
for next PR to PM maintainer.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-25 20:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 5:08 [PATCH v2] tools/cpupower: Fix incorrect size in cpuidle_state_disable() Kaushlendra Kumar
2025-09-25 20:22 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox