Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

Kees Cook 4b44cbb2 f709859f

+4 -4
+4 -4
include/linux/overflow.h
··· 42 42 * both the type-agnostic benefits of the macros while also being able to 43 43 * enforce that the return value is, in fact, checked. 44 44 */ 45 - static inline bool __must_check __must_check_overflow(bool overflow) 45 + static __always_inline bool __must_check __must_check_overflow(bool overflow) 46 46 { 47 47 return unlikely(overflow); 48 48 } ··· 327 327 * with any overflow causing the return value to be SIZE_MAX. The 328 328 * lvalue must be size_t to avoid implicit type conversion. 329 329 */ 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) 331 331 { 332 332 size_t bytes; 333 333 ··· 346 346 * with any overflow causing the return value to be SIZE_MAX. The 347 347 * lvalue must be size_t to avoid implicit type conversion. 348 348 */ 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) 350 350 { 351 351 size_t bytes; 352 352 ··· 367 367 * argument may be SIZE_MAX (or the result with be forced to SIZE_MAX). 368 368 * The lvalue must be size_t to avoid implicit type conversion. 369 369 */ 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) 371 371 { 372 372 size_t bytes; 373 373