From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Len Brown <lenb@kernel.org>
Cc: linux-pm@vger.kernel.org, Amarjeet <amarjeet@intel.com>,
Len Brown <len.brown@intel.com>
Subject: Re: [PATCH 17/18] x86_energy_perf_policy: Fix write_sysfs() return type
Date: Wed, 21 Oct 2026 19:45:44 +0300 [thread overview]
Message-ID: <atjsOHX5Uibb-CqK@ashevche-desk.local> (raw)
In-Reply-To: <777cbe6f740ab2e371df856c716ffe41117940a6.1792428130.git.len.brown@intel.com>
On Mon, Oct 19, 2026 at 12:43:38PM -0400, Len Brown wrote:
> 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().
...
> 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;
Wouldn't it be better (but I haven't checked callers of this) to have
other way around?
int ret;
...
ret = write_sysfs(path, tmp, (size_t)len + 1);
if (ret < 0)
return ret;
return 0;
> }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-10-21 16:45 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 16:43 [PATCH 0/18] x86_energy_perf_policy cleanups Len Brown
2026-10-19 16:43 ` [PATCH 01/18] x86_energy_perf_policy: Create msr_path helper Len Brown
2026-10-19 16:43 ` [PATCH 02/18] x86_energy_perf_policy: Enhance MSR probe Len Brown
2026-10-20 9:44 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 03/18] x86_energy_perf_policy: Prevent unlikely buffer overflow Len Brown
2026-10-20 9:46 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 04/18] x86_energy_perf_policy: Cleanup: Harden with strtol() Len Brown
2026-10-21 15:56 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 05/18] x86_energy_perf_policy: Cleanup: Use snprintf() for platform-profile Len Brown
2026-10-21 15:57 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 06/18] x86_energy_perf_policy: Fix optarg keyword matching Len Brown
2026-10-21 15:58 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 07/18] x86_energy_perf_policy: Cleanup: Fix potential ratio overflow Len Brown
2026-10-21 16:06 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 08/18] x86_energy_perf_policy: Bound package iteration Len Brown
2026-10-21 16:08 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 09/18] x86_energy_perf_policy: Cleanup: Define HWP window max Len Brown
2026-10-21 16:10 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 10/18] x86_energy_perf_policy: Cleanup: Define BCLK_MHZ Len Brown
2026-10-21 16:16 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 11/18] x86_energy_perf_policy: Cleanup: Check fseek() in VM path Len Brown
2026-10-21 16:19 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 12/18] x86_energy_perf_policy: Document MSRHEADER Len Brown
2026-10-21 16:31 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 13/18] x86_energy_perf_policy: Cleanup: Drop unused signal.h Len Brown
2026-10-21 16:38 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 14/18] x86_energy_perf_policy: Cleanup: Constify profile name arg Len Brown
2026-10-21 16:39 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 15/18] x86_energy_perf_policy: Cleanup: Constify HWP strings Len Brown
2026-10-21 16:39 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 16/18] x86_energy_perf_policy: Fix use-after-free in err_on_hypervisor() Len Brown
2026-10-21 16:42 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 17/18] x86_energy_perf_policy: Fix write_sysfs() return type Len Brown
2026-10-21 16:45 ` Andy Shevchenko [this message]
2026-10-19 16:43 ` [PATCH 18/18] MAINTAINERS: Add x86_energy_perf_policy Len Brown
2026-10-21 16:46 ` Andy Shevchenko
2026-10-19 18:33 ` [PATCH 01/18] x86_energy_perf_policy: Create msr_path helper Andy Shevchenko
2026-10-20 9:35 ` Andy Shevchenko
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=atjsOHX5Uibb-CqK@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=amarjeet@intel.com \
--cc=len.brown@intel.com \
--cc=lenb@kernel.org \
--cc=linux-pm@vger.kernel.org \
/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