From: Kees Cook <kees@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Johannes Berg <johannes.berg@intel.com>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-wireless@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Johannes Berg <johannes@sipsolutions.net>
Subject: Re: [PATCH v1 1/2] overflow: Allow to sum a few arguments at once
Date: Thu, 18 Jun 2026 20:47:34 -0700 [thread overview]
Message-ID: <202606182046.AE5F6A241@keescook> (raw)
In-Reply-To: <20260617112250.2791461-2-andriy.shevchenko@linux.intel.com>
On Wed, Jun 17, 2026 at 01:12:36PM +0200, Andy Shevchenko wrote:
> Convert size_add() to take variadic argument, so we can simplify users
> with using a macro only once.
Oh, this is fun. I like it. :)
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> include/linux/overflow.h | 37 ++++++++++++++++++++++++++-----------
> 1 file changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> index a8cb6319b4fb..a8b0325e73f3 100644
> --- a/include/linux/overflow.h
> +++ b/include/linux/overflow.h
> @@ -2,9 +2,10 @@
> #ifndef __LINUX_OVERFLOW_H
> #define __LINUX_OVERFLOW_H
>
> +#include <linux/args.h>
> #include <linux/compiler.h>
> -#include <linux/limits.h>
> #include <linux/const.h>
> +#include <linux/limits.h>
>
> /*
> * We need to compute the minimum and maximum values representable in a given
> @@ -337,16 +338,7 @@ static __always_inline size_t __must_check size_mul(size_t factor1, size_t facto
> return bytes;
> }
>
> -/**
> - * size_add() - Calculate size_t addition with saturation at SIZE_MAX
> - * @addend1: first addend
> - * @addend2: second addend
> - *
> - * Returns: calculate @addend1 + @addend2, both promoted to size_t,
> - * with any overflow causing the return value to be SIZE_MAX. The
> - * lvalue must be size_t to avoid implicit type conversion.
> - */
> -static __always_inline size_t __must_check size_add(size_t addend1, size_t addend2)
> +static __always_inline size_t __must_check __size_add(size_t addend1, size_t addend2)
> {
> size_t bytes;
>
> @@ -356,6 +348,29 @@ static __always_inline size_t __must_check size_add(size_t addend1, size_t adden
> return bytes;
> }
>
> +#define __size_add0(addend1, ...) \
> + __size_add(addend1, 0)
> +#define __size_add1(addend1, addend2, ...) \
> + __size_add(addend1, addend2)
> +#define __size_add2(addend1, addend2, addend3, ...) \
> + __size_add(__size_add(addend1, addend2), addend3)
> +#define __size_add3(addend1, addend2, addend3, addend4, ...) \
> + __size_add(__size_add2(addend1, addend2, addend3), addend4)
> +#define __size_add4(addend1, addend2, addend3, addend4, addend5, ...) \
> + __size_add(__size_add3(addend1, addend2, addend3, addend4), addend5)
Is 4 the max seen in practice?
--
Kees Cook
next prev parent reply other threads:[~2026-06-19 3:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 11:12 [rfc, PATCH v1 0/2] overflow: Convert size_add() to take variadic arguments Andy Shevchenko
2026-06-17 11:12 ` [PATCH v1 1/2] overflow: Allow to sum a few arguments at once Andy Shevchenko
2026-06-17 12:56 ` Johannes Berg
2026-06-17 21:30 ` David Laight
2026-06-18 6:39 ` Andy Shevchenko
2026-06-18 18:53 ` Johannes Berg
2026-06-18 21:36 ` David Laight
2026-06-19 3:47 ` Kees Cook [this message]
2026-06-19 6:45 ` Andy Shevchenko
2026-06-17 11:12 ` [PATCH v1 2/2] wifi: nl80211: Call size_add() only once Andy Shevchenko
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=202606182046.AE5F6A241@keescook \
--to=kees@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gustavoars@kernel.org \
--cc=johannes.berg@intel.com \
--cc=johannes@sipsolutions.net \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.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