From: Grigory Vasilyev <h0tc0d3@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Grigory Vasilyev <h0tc0d3@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] tools/x86_energy_perf_policy: Fix comparing int with LONG_MIN and LONG_MAX
Date: Wed, 13 Apr 2022 22:29:00 +0300 [thread overview]
Message-ID: <20220413192901.179470-1-h0tc0d3@gmail.com> (raw)
A condition that will never be met.
strtol return long value but we have int variable and strtool can
overflow it.
Remove meaningless extra overflow comparisons.
Warning:
x86_energy_perf_policy.c:337:25:
warning: result of comparison of constant 9223372036854775807
with expression of type 'int' is always false
if (i == LONG_MIN || i == LONG_MAX)
~ ^ ~~~~~~~~
x86_energy_perf_policy.c:337:8:
warning: result of comparison of constant -9223372036854775808
with expression of type 'int' is always false
if (i == LONG_MIN || i == LONG_MAX)
Signed-off-by: Grigory Vasilyev <h0tc0d3@gmail.com>
---
.../x86_energy_perf_policy/x86_energy_perf_policy.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 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 5fd9e594079c..5fd7e2d4cd0e 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
@@ -308,7 +308,7 @@ int parse_cmdline_turbo(int i)
int parse_optarg_string(char *s)
{
- int i;
+ long i;
char *endptr;
if (!strncmp(s, "default", 7))
@@ -334,15 +334,11 @@ int parse_optarg_string(char *s)
fprintf(stderr, "no digits in \"%s\"\n", s);
usage();
}
- if (i == LONG_MIN || i == LONG_MAX)
- errx(-1, "%s", s);
- if (i > 0xFF)
- errx(-1, "%d (0x%x) must be < 256", i, i);
+ if (i < 0 || i > 255)
+ errx(-1, "%ld (0x%lx) must be >= 0 and < 256", i, i);
- if (i < 0)
- errx(-1, "%d (0x%x) must be >= 0", i, i);
- return i;
+ return (int)i;
}
void parse_cmdline_all(char *s)
--
2.35.2
reply other threads:[~2022-04-13 19:29 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=20220413192901.179470-1-h0tc0d3@gmail.com \
--to=h0tc0d3@gmail.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®