Skip to contentSkip to conversation

tools/cpupower: fix error return value in cpupower_write_sysfs()

PATCH In review Kaushlendra Kumar 2 participants 2 messages Aug 28, 2025 – Sep 16, 2025 CPU power monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/cpupower: fix error return value in cpupower_write_sysfs()

The cpupower_write_sysfs() function currently returns -1 on write failure, but the function signature indicates it should return an unsigned int. Returning -1 from an unsigned function results in a large positive value rather than indicating an error condition.

Fix this by returning 0 on failure, which is more appropriate for an unsigned return type and maintains consistency with typical success/failure semantics where 0 indicates failure and non-zero indicates success (bytes written).

---
 tools/power/cpupower/lib/cpupower.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/cpupower/lib/cpupower.c +1 -1
index ce8dfb8e46ab..d7f7ec6f151c 100644
@@ -56,7 +56,7 @@ unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen)
 	if (numwritten < 1) {
 		perror(path);
 		close(fd);
-		return -1;
+		return 0;
 	}
 
 	close(fd);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · Kaushlendra Kumar

The cpupower_write_sysfs() function currently returns -1 on write failure, but the function signature indicates it should return an unsigned int. Returning -1 from an unsigned function results in a large positive value rather than indicating an error condition.

Quoted 7 lines

Fix this by returning 0 on failure, which is more appropriate for an unsigned return type and maintains consistency with typical success/failure semantics where 0 indicates failure and non-zero indicates success (bytes written).

---

Thanks. Applied to git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git cpupower branch.

thanks,
-- Shuah