[PATCH] efivarfs: Suppress false-positive kmemleak warning for sfi

From: Breno Leitao
Date: Tue Jul 15 2025 - 05:32:20 EST


When kmemleak is enabled, it incorrectly reports the sfi structure
allocated during efivarfs_init_fs_context() as leaked:

unreferenced object 0xffff888146250b80 (size 64):
__kmalloc_cache_noprof
efivarfs_init_fs_context
...

On module unload, this object is freed in efivarfs_kill_sb(), confirming
no actual leak. Also, kfree(sfi) is called at efivarfs_kill_sb(). I am
not able to explain why kmemleak detected it as a leak. To silence this
false-positive, mark the sfi allocation as ignored by kmemleak right
after allocation.

This ensures clearer leak diagnostics for this allocation path.

Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
fs/efivarfs/super.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c
index c900d98bf4945..5f867ad2005ae 100644
--- a/fs/efivarfs/super.c
+++ b/fs/efivarfs/super.c
@@ -19,6 +19,7 @@
#include <linux/notifier.h>
#include <linux/printk.h>
#include <linux/namei.h>
+#include <linux/kmemleak.h>

#include "internal.h"
#include "../internal.h"
@@ -498,6 +499,7 @@ static int efivarfs_init_fs_context(struct fs_context *fc)
if (!sfi)
return -ENOMEM;

+ kmemleak_ignore(sfi);
sfi->mount_opts.uid = GLOBAL_ROOT_UID;
sfi->mount_opts.gid = GLOBAL_ROOT_GID;


---
base-commit: 8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2
change-id: 20250714-kmemleak_efi-bedfe48a304d

Best regards,
--
Breno Leitao <leitao@xxxxxxxxxx>