From: David Laight <david.laight.linux@gmail.com>
To: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
Cc: Rodrigo Alencar via B4 Relay
<devnull+rodrigo.alencar.analog.com@kernel.org>,
rodrigo.alencar@analog.com, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, Jonathan Cameron <jic23@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v8 02/10] lib: kstrtox: add kstrntoull() helper
Date: Tue, 10 Mar 2026 10:50:27 +0000 [thread overview]
Message-ID: <20260310105027.08b93187@pumpkin> (raw)
In-Reply-To: <zhjkurpwbuvirh3k4a4c3lfeu5semu4rjszvej4hnx7scjyk2q@v4r7oqexwsjl>
On Tue, 10 Mar 2026 09:26:11 +0000
Rodrigo Alencar <455.rodrigo.alencar@gmail.com> wrote:
> On 26/03/04 11:41AM, Rodrigo Alencar wrote:
> > On 26/03/04 10:16AM, David Laight wrote:
> > > On Tue, 03 Mar 2026 13:27:07 +0000
> > > Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org> wrote:
> > >
> > > > From: Rodrigo Alencar <rodrigo.alencar@analog.com>
> > > >
> > > > Add kstrntoull() function, which converts a string to an ULL with a max
> > > > character limit. The function is an alternative integer parsing function
> > > > that does not require a null-terminated string. It becomes a better option
> > > > over simple_strtoull() or kstrtoull() when parsing integers from a buffer
> > > > with custom delimiters without having to create temporary copies.
> > > > The function is consumed inside the implementation _kstrtoull(),
> > > > promoting reuse.
> > >
> > > If you've got custom delimiters use a function that returns a pointer
> > > to the character that terminated the conversion.
> > > They save you having to find the delimiter as well as taking a copy.
> >
> > understood, how about this prototype then:
> >
> > const char __must_check *kstrntoull(const char *s, unsigned int base,
> > unsigned long long *res, size_t max_chars);
> >
> > to be used like:
> >
> > end = kstrntoull(s, base, &res, INT_MAX);
> > if (IS_ERR(end)) {
> > /* return or handle error */
> > return PTR_ERR(end);
> > }
>
> Hi David,
>
> Do you have any other feedback? the function prototype can also be changed as
> follows:
>
> int __must_check *kstrntoull(const char *s, const char **endp, unsigned int base,
> unsigned long long *res, size_t max_chars);
>
> so that a pointer to the terminated character is passes as a parameter.
> which one would be the preference?
>
I really don't see why you need to add 'yet another' function for parsing
integers.
Having to pre-scan the string for a separator seems just wrong.
The userspace strtoul() family do everything quite nicely apart from
overflow/limit checking.
There are a few options for overflow:
- Ignore it, this used to be what posix/sus allowed for command lines.
- Saturate.
- Return a pointer to the digit that makes the value too big as the
termination character - since the code will typically expect one
of ",.:-" this will be a syntax error.
It might be worth adding a parameter for the maximum value.
Then you only need one real function for 32bit and 64bit values.
But you also really want the use the function return value for the
converted number (for all sorts of reasons).
David
next prev parent reply other threads:[~2026-03-10 10:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 13:27 [PATCH v8 00/10] ADF41513/ADF41510 PLL frequency synthesizers Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 01/10] dt-bindings: iio: frequency: add adf41513 Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 02/10] lib: kstrtox: add kstrntoull() helper Rodrigo Alencar via B4 Relay
2026-03-03 13:49 ` Andy Shevchenko
2026-03-03 14:16 ` Rodrigo Alencar
2026-03-04 10:02 ` Rodrigo Alencar
2026-03-20 11:16 ` Rodrigo Alencar
2026-03-20 11:50 ` Andy Shevchenko
2026-03-20 12:08 ` Rodrigo Alencar
2026-03-20 12:24 ` Andy Shevchenko
2026-03-20 12:41 ` Rodrigo Alencar
2026-03-20 14:17 ` Andy Shevchenko
2026-03-20 14:44 ` David Laight
2026-03-04 10:16 ` David Laight
2026-03-04 11:41 ` Rodrigo Alencar
2026-03-10 9:26 ` Rodrigo Alencar
2026-03-10 10:50 ` David Laight [this message]
2026-03-10 11:30 ` Rodrigo Alencar
2026-03-03 13:27 ` [PATCH v8 03/10] lib: test-kstrtox: add tests for kstrntoull() Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 04/10] iio: core: add fixed point parsing with 64-bit parts Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 05/10] iio: test: add kunit test for fixed-point parsing Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 06/10] iio: frequency: adf41513: driver implementation Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 07/10] iio: frequency: adf41513: handle LE synchronization feature Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 08/10] iio: frequency: adf41513: features on frequency change Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 09/10] docs: iio: add documentation for adf41513 driver Rodrigo Alencar via B4 Relay
2026-03-03 13:27 ` [PATCH v8 10/10] Documentation: ABI: testing: add common ABI file for iio/frequency Rodrigo Alencar via B4 Relay
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=20260310105027.08b93187@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=455.rodrigo.alencar@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=devnull+rodrigo.alencar.analog.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=rodrigo.alencar@analog.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