The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Dmitry Antipov <dmantipov@yandex.ru>,
	Petr Mladek <pmladek@suse.com>,
	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 1/2] kstrtox: Make _parse_integer() take variadic arguments
Date: Wed, 3 Jun 2026 11:37:50 +0100	[thread overview]
Message-ID: <20260603113750.71c93100@pumpkin> (raw)
In-Reply-To: <20260602203706.103449-2-andriy.shevchenko@linux.intel.com>

On Tue,  2 Jun 2026 22:29:46 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Instead of having different functions that just use default parameters,
> combine those to use variadic arguments, so the user may call it using
> the same name.

Adding a default final parameter can be done generically:

#define one(v) v
#define first(v, ...) v
#define dflt(d, ...) first(__VA_OPT__(one(__VA_ARGS__) ,) d)

int foo(int, int);
#define foo(a, ...) foo(a, dflt(42, ## __VA_ARGS__))

See: https://godbolt.org/z/x5aao7reK

-- David

> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/kstrtox.c | 6 ------
>  lib/kstrtox.h | 9 ++++++++-
>  2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index edc4eb7c1bca..adc03e27e4a2 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -94,12 +94,6 @@ unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned lon
>  	return rv | overflow;
>  }
>  
> -noinline
> -unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
> -{
> -	return _parse_integer_limit(s, base, p, INT_MAX);
> -}
> -
>  static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
>  {
>  	unsigned long long _res;
> diff --git a/lib/kstrtox.h b/lib/kstrtox.h
> index 158c400ca865..6c7ca3b67429 100644
> --- a/lib/kstrtox.h
> +++ b/lib/kstrtox.h
> @@ -2,10 +2,17 @@
>  #ifndef _LIB_KSTRTOX_H
>  #define _LIB_KSTRTOX_H
>  
> +#include <linux/args.h>
> +
>  #define KSTRTOX_OVERFLOW	(1U << 31)
>  const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
>  unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned long long *res,
>  				  size_t max_chars);
> -unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res);
> +
> +#define _parse_integer0(s, base, res, ...)						\
> +	_parse_integer_limit(s, base, res, INT_MAX);
> +
> +#define _parse_integer(s, base, res, ...)						\
> +	CONCATENATE(_parse_integer, COUNT_ARGS(__VA_ARGS__))(s, base, res, __VA_ARGS__)
>  
>  #endif


  parent reply	other threads:[~2026-06-03 10:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 20:29 [PATCH v1 0/2] kstrtox: make _parse_integer() flexible 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 [this message]
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
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=20260603113750.71c93100@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --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