mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] overflow: Make sure size helpers are always inlined
Date: Tue, 24 Feb 2026 17:41:39 +0900	[thread overview]
Message-ID: <e185faba-1b65-4831-b077-68fa10d0554a@embeddedor.com> (raw)
In-Reply-To: <20260224232451.work.614-kees@kernel.org>



On 2/25/26 08:24, Kees Cook wrote:
> With kmalloc_obj() performing implicit size calculations, the embedded
> size_mul() calls, while marked inline, were not always being inlined.
> I noticed a couple places where allocations were making a call out for
> things that would otherwise be compile-time calculated. Force the
> compilers to always inline these calculations.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
-Gustavo

> ---
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: <linux-hardening@vger.kernel.org>
> ---
>   include/linux/overflow.h | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> index eddd987a8513..a8cb6319b4fb 100644
> --- a/include/linux/overflow.h
> +++ b/include/linux/overflow.h
> @@ -42,7 +42,7 @@
>    * both the type-agnostic benefits of the macros while also being able to
>    * enforce that the return value is, in fact, checked.
>    */
> -static inline bool __must_check __must_check_overflow(bool overflow)
> +static __always_inline bool __must_check __must_check_overflow(bool overflow)
>   {
>   	return unlikely(overflow);
>   }
> @@ -327,7 +327,7 @@ static inline bool __must_check __must_check_overflow(bool overflow)
>    * with any overflow causing the return value to be SIZE_MAX. The
>    * lvalue must be size_t to avoid implicit type conversion.
>    */
> -static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
> +static __always_inline size_t __must_check size_mul(size_t factor1, size_t factor2)
>   {
>   	size_t bytes;
>   
> @@ -346,7 +346,7 @@ static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
>    * with any overflow causing the return value to be SIZE_MAX. The
>    * lvalue must be size_t to avoid implicit type conversion.
>    */
> -static 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;
>   
> @@ -367,7 +367,7 @@ static inline size_t __must_check size_add(size_t addend1, size_t addend2)
>    * argument may be SIZE_MAX (or the result with be forced to SIZE_MAX).
>    * The lvalue must be size_t to avoid implicit type conversion.
>    */
> -static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
> +static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
>   {
>   	size_t bytes;
>   


      reply	other threads:[~2026-02-24 23:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 23:24 Kees Cook
2026-02-24  8:41 ` Gustavo A. R. Silva [this message]

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=e185faba-1b65-4831-b077-68fa10d0554a@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®