Re: [PATCH v8 02/10] lib: kstrtox: add kstrntoull() helper
From: Rodrigo Alencar
Date: Tue Mar 03 2026 - 09:23:17 EST
On 26/03/03 03:49PM, Andy Shevchenko wrote:
> On Tue, Mar 03, 2026 at 01:27:07PM +0000, Rodrigo Alencar via B4 Relay wrote:
>
> > 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
>
> null --> NUL
>
> > 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.
>
> But this will not properly convert 0000000000000000000000000000000000000000100,
> for example, if the max_chars say set to 20.
Why would I want that? truncation will happen in the case and the value will
be zero. max_chars can be zet to INT_MAX/SIZE_MAX if you want to get 100.
> Also kstrto*() have a common idea behind to consume the only \n and allowed
> digits. This (naming) doesn't fit into the kstrto*() category.
mmm ok, but include/linux/kstrtox.h is the right place for this? how about just
strntoull()? I feel like a safe_ prefix does not make much sense if it is
only to differentiate from simple_strto*(), which should have been safe at
the first place.
--
Kind regards,
Rodrigo Alencar