Skip to content

Commit 4b44cbb

Browse files
committed
overflow: Make sure size helpers are always inlined
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. Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://patch.msgid.link/20260224232451.work.614-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent f709859 commit 4b44cbb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

include/linux/overflow.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* both the type-agnostic benefits of the macros while also being able to
4343
* enforce that the return value is, in fact, checked.
4444
*/
45-
static inline bool __must_check __must_check_overflow(bool overflow)
45+
static __always_inline bool __must_check __must_check_overflow(bool overflow)
4646
{
4747
return unlikely(overflow);
4848
}
@@ -327,7 +327,7 @@ static inline bool __must_check __must_check_overflow(bool overflow)
327327
* with any overflow causing the return value to be SIZE_MAX. The
328328
* lvalue must be size_t to avoid implicit type conversion.
329329
*/
330-
static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
330+
static __always_inline size_t __must_check size_mul(size_t factor1, size_t factor2)
331331
{
332332
size_t bytes;
333333

@@ -346,7 +346,7 @@ static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
346346
* with any overflow causing the return value to be SIZE_MAX. The
347347
* lvalue must be size_t to avoid implicit type conversion.
348348
*/
349-
static inline size_t __must_check size_add(size_t addend1, size_t addend2)
349+
static __always_inline size_t __must_check size_add(size_t addend1, size_t addend2)
350350
{
351351
size_t bytes;
352352

@@ -367,7 +367,7 @@ static inline size_t __must_check size_add(size_t addend1, size_t addend2)
367367
* argument may be SIZE_MAX (or the result with be forced to SIZE_MAX).
368368
* The lvalue must be size_t to avoid implicit type conversion.
369369
*/
370-
static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
370+
static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
371371
{
372372
size_t bytes;
373373

0 commit comments

Comments
 (0)