mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Dmitry Antipov <dmantipov@yandex.ru>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	rodrigo.alencar@analog.com, dlechner@baylibre.com,
	jic23@kernel.org
Subject: Re: [PATCH v1 0/2] kstrtox: make _parse_integer() flexible
Date: Wed, 3 Jun 2026 16:53:49 +0300	[thread overview]
Message-ID: <aiAx7Qd8E2HjIbwO@ashevche-desk.local> (raw)
In-Reply-To: <gedxlgidwh6drnkxlqoq7eq2c5pyjdffkl3ccvppf6r4txerdl@bna3u7jqjpgj>

On Wed, Jun 03, 2026 at 12:51:09PM +0100, Rodrigo Alencar wrote:
> On 26/06/03 01:23PM, Petr Mladek wrote:
> > On Tue 2026-06-02 22:29:45, Andy Shevchenko wrote:
> > > Currently every new wrapper on _parse_integer_limit() will need a new name
> > > to share with users while keeping some optional arguments to be initialised
> > > explicitly. Since there is an attempt to expand this more, I decided to
> > > suggest this mini series to avoid namespace pollution and unneeded churn in
> > > the future.
> > > 
> > > To expand this API more, the possible future change may be:
> > > 
> > >  unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned long long *res,
> > > -                                  size_t max_chars);
> > > +                                  size_t max_chars, $new_opt_arg);
> > > 
> > >  #define _parse_integer0(s, base, res, ...)                                              \
> > > -        _parse_integer_limit(s, base, res, INT_MAX);
> > > +        _parse_integer_limit(s, base, res, INT_MAX, $new_opt_arg=$default);
> > > 
> > >  #define _parse_integer1(s, base, res, max_chars, ...)                                   \
> > > -        _parse_integer_limit(s, base, res, max_chars);
> > > +        _parse_integer_limit(s, base, res, max_chars, $new_opt_arg=$default);
> > > 
> > > +#define _parse_integer2(s, base, res, max_chars, new_opt_arg, ...)                      \
> > > +        _parse_integer_limit(s, base, res, max_chars, new_opt_arg);
> > 
> > I guess that this is about _parse_integer_limit_init() from
> > https://lore.kernel.org/all/20260531-adf41513-iio-driver-v15-2-da09adf1c0dd@analog.com/
> > 
> > I personally find
> > 
> >     _parse_integer(*s, base. *res)
> >     _parse_integer_limit(*s, base, *res, max_chars)
> >     _parse_integer_limit_init(*s, base, init, *res, max_chars)
> 
> What could also be done is having a _parse_integer_ext() that would
> contain all the necessary arguments (one that should be indicated
> not to be used) and define all the other variations as static inline
> functions. I suppose that combines both ideas, being a pattern that
> is also used elsewhere:
> 
> 	devm_regulator_get()
> 	devm_regulator_get_enable()
> 	devm_regulator_get_enable_optional() 

devm_regulator_get*() are public APIs and that split might make sense. The
_parse_integer() is internal to printf() implementation and wrappers around it,
so I don't think we should really be so picky. TL;DR: I think my approach is
good enough and makes not much of turbulence here, perhaps a comment would be
nice to have to explain the list of optional arguments.

> > a bit more self-explanatory than
> > 
> >     _parse_integer(*s, base. *res)
> >     _parse_integer(*s, base, *res, max_chars)
> >     _parse_integer(*s, base, *res, max_chars, init)
> > 
> > especially when the meaning of the arguments need not be obvious
> > when the function is used in the code.
> > 
> > Also the macro magic increases the complexity of the code.
> > 
> > On the other hand, I do not have strong opinion. It is not a big deal.
> > I am not going to block it.

Would you give your tag in case Rodrigo wants to incorporate these into his
series and go via IIO tree? (I think that these two makes sense to put into
immutable branch/tag and share with the users).

> > > So you got the idea. (It is roughly overloaded function in OOP.)

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2026-06-03 13:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 20:29 Andy Shevchenko
2026-06-02 20:29 ` [PATCH v1 1/2] kstrtox: Make _parse_integer() take variadic arguments Andy Shevchenko
2026-06-03  6:47   ` Andy Shevchenko
2026-06-03 10:37   ` David Laight
2026-06-03 10:54     ` Andy Shevchenko
2026-06-03 10:56       ` Andy Shevchenko
2026-06-03 11:34         ` David Laight
2026-06-02 20:29 ` [PATCH v1 2/2] vsprintf: Convert to use _parse_integer() instead of _parse_integer_limit() Andy Shevchenko
2026-06-03 11:23 ` [PATCH v1 0/2] kstrtox: make _parse_integer() flexible Petr Mladek
2026-06-03 11:51   ` Rodrigo Alencar
2026-06-03 12:10     ` Rodrigo Alencar
2026-06-03 13:58       ` Andy Shevchenko
2026-06-03 13:53     ` Andy Shevchenko [this message]
2026-06-04  6:59       ` Petr Mladek
2026-06-04  7:19         ` Andy Shevchenko
2026-06-04  7:48           ` Rodrigo Alencar

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=aiAx7Qd8E2HjIbwO@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=455.rodrigo.alencar@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dlechner@baylibre.com \
    --cc=dmantipov@yandex.ru \
    --cc=jic23@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=rodrigo.alencar@analog.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.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®