linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: "Wang, Wei W" <wei.w.wang@intel.com>
Cc: Vipin Sharma <vipinsh@google.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"dmatlack@google.com" <dmatlack@google.com>,
	"andrew.jones@linux.dev" <andrew.jones@linux.dev>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 3/5] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi()
Date: Wed, 26 Oct 2022 15:10:53 +0000	[thread overview]
Message-ID: <Y1lN/YRc2B3KoR+n@google.com> (raw)
In-Reply-To: <DS0PR11MB63733C7CA0B1497215B40F8DDC309@DS0PR11MB6373.namprd11.prod.outlook.com>

On Wed, Oct 26, 2022, Wang, Wei W wrote:
> On Saturday, October 22, 2022 5:18 AM, Vipin Sharma wrote:
> > +int atoi_paranoid(const char *num_str)
> > +{
> > +	char *end_ptr;
> > +	long num;
> > +
> > +	errno = 0;
> > +	num = strtol(num_str, &end_ptr, 10);
> 
> Why not use strtoull here?

This intended to be a drop in replacement for atoi(), which allows negative
numbers.

> Negative numbers will result in a huge "unsigned long long" number,
> and this will be captured by your TEST_ASSERT(num >= INT_MIN) below.

As above, we want to allow negative numbers, e.g. memslot_perf_test.c uses '-1'
to indicate "as many slots as possible".

It's unlikely a test will As unlikely as 

> Then we don't need patch 4, I think.

Even if this low level helper disallowed negative numbers, patch 4 still has value
in that the wrappers make the code self-documenting, i.e. makes it very obvious
what input values are allowed.

  reply	other threads:[~2022-10-26 15:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 21:18 [PATCH v6 0/5] dirty_log_perf_test vCPU pinning Vipin Sharma
2022-10-21 21:18 ` [PATCH v6 1/5] KVM: selftests: Add missing break between -e and -g option in dirty_log_perf_test Vipin Sharma
2022-10-21 21:18 ` [PATCH v6 2/5] KVM: selftests: Put command line options in alphabetical order " Vipin Sharma
2022-10-26  2:09   ` Wang, Wei W
2022-10-26 15:04     ` Sean Christopherson
2022-10-26 17:45       ` Vipin Sharma
2022-10-21 21:18 ` [PATCH v6 3/5] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi() Vipin Sharma
2022-10-26  2:16   ` Wang, Wei W
2022-10-26 15:10     ` Sean Christopherson [this message]
2022-10-21 21:18 ` [PATCH v6 4/5] KVM: selftests: Add atoi_positive() and atoi_non_negative() for input validation Vipin Sharma
2022-10-21 21:18 ` [PATCH v6 5/5] KVM: selftests: Allowing running dirty_log_perf_test on specific CPUs Vipin Sharma
2022-10-26  2:27   ` Wang, Wei W
2022-10-26 15:44     ` Sean Christopherson
2022-10-26 18:17       ` Vipin Sharma
2022-10-27 12:03       ` Wang, Wei W
2022-10-27 15:56         ` Sean Christopherson
2022-10-27 20:02           ` Vipin Sharma
2022-10-27 20:23             ` Sean Christopherson
2022-10-28  2:11             ` Wang, Wei W
2022-10-28 17:37               ` Vipin Sharma

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=Y1lN/YRc2B3KoR+n@google.com \
    --to=seanjc@google.com \
    --cc=andrew.jones@linux.dev \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vipinsh@google.com \
    --cc=wei.w.wang@intel.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;
as well as URLs for NNTP newsgroup(s).