summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/memslot_perf_test.c
diff options
context:
space:
mode:
authorVipin Sharma <vipinsh@google.com>2022-11-03 22:17:18 +0300
committerSean Christopherson <seanjc@google.com>2022-11-16 21:03:24 +0300
commit0001725d0f9b5d749540021befb67c117d566416 (patch)
tree5789cf5ac497191de06a10ac0c22e577a382285f /tools/testing/selftests/kvm/memslot_perf_test.c
parentc15bdebb32ddc73faac5e5180d6997b360e81619 (diff)
downloadlinux-0001725d0f9b5d749540021befb67c117d566416.tar.xz
KVM: selftests: Add atoi_positive() and atoi_non_negative() for input validation
Many KVM selftests take command line arguments which are supposed to be positive (>0) or non-negative (>=0). Some tests do these validation and some missed adding the check. Add atoi_positive() and atoi_non_negative() to validate inputs in selftests before proceeding to use those values. Signed-off-by: Vipin Sharma <vipinsh@google.com> Reviewed-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20221103191719.1559407-7-vipinsh@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/memslot_perf_test.c')
-rw-r--r--tools/testing/selftests/kvm/memslot_perf_test.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c
index 4bae9e3f5ca1..330aaef1c02f 100644
--- a/tools/testing/selftests/kvm/memslot_perf_test.c
+++ b/tools/testing/selftests/kvm/memslot_perf_test.c
@@ -892,33 +892,21 @@ static bool parse_args(int argc, char *argv[],
}
break;
case 'f':
- targs->tfirst = atoi_paranoid(optarg);
- if (targs->tfirst < 0) {
- pr_info("First test to run has to be non-negative\n");
- return false;
- }
+ targs->tfirst = atoi_non_negative("First test", optarg);
break;
case 'e':
- targs->tlast = atoi_paranoid(optarg);
- if (targs->tlast < 0 || targs->tlast >= NTESTS) {
+ targs->tlast = atoi_non_negative("Last test", optarg);
+ if (targs->tlast >= NTESTS) {
pr_info("Last test to run has to be non-negative and less than %zu\n",
NTESTS);
return false;
}
break;
case 'l':
- targs->seconds = atoi_paranoid(optarg);
- if (targs->seconds < 0) {
- pr_info("Test length in seconds has to be non-negative\n");
- return false;
- }
+ targs->seconds = atoi_non_negative("Test length", optarg);
break;
case 'r':
- targs->runs = atoi_paranoid(optarg);
- if (targs->runs <= 0) {
- pr_info("Runs per test has to be positive\n");
- return false;
- }
+ targs->runs = atoi_positive("Runs per test", optarg);
break;
}
}