Marco Elver
unread,Sep 3, 2025, 2:00:11 AMSep 3Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Nathan Chancellor, Alexander Potapenko, Dmitry Vyukov, kasa...@googlegroups.com, linu...@kvack.org, ll...@lists.linux.dev
On Wed, 3 Sept 2025 at 02:07, Nathan Chancellor <
nat...@kernel.org> wrote:
>
> Hi kfence folks,
>
> After [1] in clang, I am seeing an instance of this pop up in
> mm/kfence/kfence_test.c on linux-6.6.y and linux-6.1.y:
>
> mm/kfence/kfence_test.c:723:8: error: allocation of insufficient size '0' for type 'char' with size '1' [-Werror,-Walloc-size]
> 723 | buf = krealloc(buf, 0, GFP_KERNEL); /* Free. */
> | ^
>
> I do not see this in linux-6.12.y or newer but I wonder if that is just
> because the memory allocation profiling adds some indirection that makes
> it harder for clang to perform this analysis?
It shouldn't, there's still a direct call:
> void * __must_check krealloc_noprof(const void *objp, size_t new_size,
> gfp_t flags) __realloc_size(2);
> #define krealloc(...)
alloc_hooks(krealloc_noprof(__VA_ARGS__))
> Should this warning just be silenced for this translation unit or is
> there some other fix that could be done here?
It should be silenced. I'm surprised that they'd e.g. warn about
malloc(0), which is well defined, and in the kernel, we also have
0-sized kmalloc (incl krealloc) allocations being well-defined. As
long as the returned pointer isn't used, there's no UB. I guess doing
an explicit 0-sized alloc is not something anyone should do normally I
guess, so the warning ought to prevent that, but in the test case we
explicitly want that.