overflow.h: Add comment documenting __ab_c_size()
__ab_c_size() is a somewhat opaque name. Document its purpose, and while at it, rename the parameters to actually match the abc naming. [ bp: glued a complete patch from chunks on LKML. ] Reported-by: Borislav Petkov <bp@suse.de> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Kees Cook <keescook@chromium.org> Cc: Matthew Wilcox <willy@infradead.org> Link: https://lkml.kernel.org/r/20190405045711.30339-1-bp@alien8.de
This commit is contained in:
parent
79a3aaa7b8
commit
e0478542cf
|
@ -278,11 +278,15 @@ static inline __must_check size_t array3_size(size_t a, size_t b, size_t c)
|
|||
return bytes;
|
||||
}
|
||||
|
||||
static inline __must_check size_t __ab_c_size(size_t n, size_t size, size_t c)
|
||||
/*
|
||||
* Compute a*b+c, returning SIZE_MAX on overflow. Internal helper for
|
||||
* struct_size() below.
|
||||
*/
|
||||
static inline __must_check size_t __ab_c_size(size_t a, size_t b, size_t c)
|
||||
{
|
||||
size_t bytes;
|
||||
|
||||
if (check_mul_overflow(n, size, &bytes))
|
||||
if (check_mul_overflow(a, b, &bytes))
|
||||
return SIZE_MAX;
|
||||
if (check_add_overflow(bytes, c, &bytes))
|
||||
return SIZE_MAX;
|
||||
|
|
Loading…
Reference in New Issue