From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: lenb@kernel.org
Cc: linux-pm@vger.kernel.org,
Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH v2] tools/power turbostat: Use strtoul() for iteration parsing
Date: Mon, 8 Dec 2025 08:38:04 +0530 [thread overview]
Message-ID: <20251208030804.2266670-1-kaushlendra.kumar@intel.com> (raw)
Replace strtod() with strtoul() and check errno for -n/-N options, since
num_iterations and header_iterations are unsigned long counters. Reject
zero and conversion errors; negative inputs wrap to large positive values
per standard unsigned semantics.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
v2: Use strtoul() + errno instead of strtod() with signed validation
per review feedback
tools/power/x86/turbostat/turbostat.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index da51d430c8af..822637911978 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -11160,18 +11160,20 @@ void cmdline(int argc, char **argv)
/* Parsed earlier */
break;
case 'n':
- num_iterations = strtod(optarg, NULL);
+ num_iterations = strtoul(optarg, NULL, 0);
+ errno = 0;
- if (num_iterations <= 0) {
- fprintf(outf, "iterations %d should be positive number\n", num_iterations);
+ if (errno || num_iterations == 0) {
+ fprintf(outf, "invalid iteration count: %s\n", optarg);
exit(2);
}
break;
case 'N':
- header_iterations = strtod(optarg, NULL);
+ header_iterations = strtoul(optarg, NULL, 0);
+ errno = 0;
- if (header_iterations <= 0) {
- fprintf(outf, "iterations %d should be positive number\n", header_iterations);
+ if (errno || header_iterations == 0) {
+ fprintf(outf, "invalid header iteration count: %s\n", optarg);
exit(2);
}
break;
--
2.34.1
reply other threads:[~2025-12-08 3:10 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=20251208030804.2266670-1-kaushlendra.kumar@intel.com \
--to=kaushlendra.kumar@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;
as well as URLs for NNTP newsgroup(s).