]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
of: reserved-memory: Do not make kmemleak ignore freed address
authorZijun Hu <quic_zijuhu@quicinc.com>
Thu, 9 Jan 2025 13:27:01 +0000 (21:27 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:50:07 +0000 (12:50 +0100)
[ Upstream commit 29091a52562bca4d6e678dd8f0085dac119d6a21 ]

early_init_dt_alloc_reserved_memory_arch() will free address @base when
suffers memblock_mark_nomap() error, but it still makes kmemleak ignore
the freed address @base via kmemleak_ignore_phys().

That is unnecessary, besides, also causes unnecessary warning messages:

kmemleak_ignore_phys()
 -> make_black_object()
    -> paint_ptr()
       -> kmemleak_warn() // warning message here.

Fix by avoiding kmemleak_ignore_phys() when suffer the error.

Fixes: 658aafc8139c ("memblock: exclude MEMBLOCK_NOMAP regions from kmemleak")
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20250109-of_core_fix-v4-10-db8a72415b8c@quicinc.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/of/of_reserved_mem.c

index 6ec668ae2d6fa1e361349cd72c5b0234f273acb6..8d6ca796d9ffacc04f8930185067c40876b95275 100644 (file)
@@ -50,7 +50,8 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
                        memblock_free(base, size);
        }
 
-       kmemleak_ignore_phys(base);
+       if (!err)
+               kmemleak_ignore_phys(base);
 
        return err;
 }