mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: amarjeet@intel.com
To: Len Brown <len.brown@intel.com>
Cc: Kaushlendra Kumar <kaushlendra.kumar@intel.com>,
	Malaya Kumar Rout <mrout@redhat.com>,
	linux-kernel@vger.kernel.org, Amarjeet <amarjeet@intel.com>
Subject: [PATCH] tools/power/x86: Fix write_sysfs() return type
Date: Tue, 28 Jul 2026 13:24:22 +0530	[thread overview]
Message-ID: <20260728075422.10977-1-amarjeet@intel.com> (raw)

From: Amarjeet <amarjeet@intel.com>

write_sysfs() returns an unsigned int even though it returns -1 when
write() fails. This converts the error to UINT_MAX and can cause callers
that treat a nonzero return value as success to miss the failure.

Use ssize_t to match write(), update the receiving variable accordingly,
and explicitly require a positive result in sysfs_write_string().

Signed-off-by: Amarjeet <amarjeet@intel.com>
---
 .../x86/x86_energy_perf_policy/x86_energy_perf_policy.c   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
index 0dc959e30076..6db7620e7b00 100644
--- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
+++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
@@ -867,7 +867,7 @@ static unsigned int read_sysfs(const char *path, char *buf, size_t buflen)
 	return (unsigned int)numread;
 }
 
-static unsigned int write_sysfs(const char *path, char *buf, size_t buflen)
+static ssize_t write_sysfs(const char *path, char *buf, size_t buflen)
 {
 	ssize_t numwritten;
 	int fd;
@@ -886,7 +886,7 @@ static unsigned int write_sysfs(const char *path, char *buf, size_t buflen)
 
 	close(fd);
 
-	return (unsigned int)numwritten;
+	return numwritten;
 }
 
 static int sysfs_read_string(const char *path, char *buf, size_t buflen)
@@ -911,7 +911,7 @@ static int sysfs_write_string(const char *path, const char *buf)
 	len = snprintf(tmp, sizeof(tmp), "%s\n", buf);
 	if (len < 0 || len >= (int)sizeof(tmp))
 		return -1;
-	return write_sysfs(path, tmp, (size_t)len + 1) ? 0 : -1;
+	return write_sysfs(path, tmp, (size_t)len + 1) > 0 ? 0 : -1;
 }
 
 void print_hwp_cap(int cpu, struct msr_hwp_cap *cap, char *str)
@@ -1016,7 +1016,7 @@ static int set_epb_sysfs(int cpu, int val)
 	char path[SYSFS_PATH_MAX];
 	char linebuf[3];
 	char *endp;
-	int ret;
+	ssize_t ret;
 
 	if (!has_epb)
 		return -1;
-- 
2.34.1


                 reply	other threads:[~2026-07-28  7:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260728075422.10977-1-amarjeet@intel.com \
    --to=amarjeet@intel.com \
    --cc=kaushlendra.kumar@intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrout@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®