Re: [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning

From: Borislav Petkov

Date: Tue Apr 07 2026 - 14:56:22 EST


On Tue, Apr 07, 2026 at 09:02:00AM -0700, Reinette Chatre wrote:
> Building resctrl with extra checks ("W=12") produces the following warning:
> .../include/linux/ucopysize.h:22:17: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
> 22 | __check_object_size(ptr, n, to_user);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> .../include/linux/ucopysize.h: In function ‘pseudo_lock_measure_trigger’:
> .../include/linux/ucopysize.h:10:13: note: by argument 1 of type ‘const void *’ to ‘__check_object_size’ declared here
> 10 | extern void __check_object_size(const void *ptr, unsigned long n,
> | ^~~~~~~~~~~~~~~~~~~
> .../fs/resctrl/pseudo_lock.c:754:14: note: ‘buf’ declared here
> 754 | char buf[32];
> | ^~~
>
> __check_object_size() ensures the provided buffer is within a valid location
> but does not read from the uninitialized buffer. Even so, initialize the
> buffer to silence the warning to help resctrl have a cleaner build.
>
> Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
> ---
> fs/resctrl/pseudo_lock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
> index fa3687d69ebd..e1e9134474f4 100644
> --- a/fs/resctrl/pseudo_lock.c
> +++ b/fs/resctrl/pseudo_lock.c
> @@ -750,8 +750,8 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
> size_t count, loff_t *ppos)
> {
> struct rdtgroup *rdtgrp = file->private_data;
> + char buf[32] = {};

AFAIU, you're not leaking any uninitialized stack data from that buffer,
right?

If so, why do you care about some silly build warning and are willing to waste
a 32-byte memset on every function entry?

There's a reason those warnings are behind W= ...

:-)

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette