• Frank Rowand's avatar
    of: fix memory leak related to safe_name() · d9fc8807
    Frank Rowand authored
    Fix a memory leak resulting from memory allocation in safe_name().
    This patch fixes all call sites of safe_name().
    
    Mathieu Malaterre reported the memory leak on boot:
    
    On my PowerMac device-tree would generate a duplicate name:
    
    [    0.023043] device-tree: Duplicate name in PowerPC,G4@0, renamed to "l2-cache#1"
    
    in this case a newly allocated name is generated by `safe_name`. However
    in this case it is never deallocated.
    
    The bug was found using kmemleak reported as:
    
    unreferenced object 0xdf532e60 (size 32):
      comm "swapper", pid 1, jiffies 4294892300 (age 1993.532s)
      hex dump (first 32 bytes):
        6c 32 2d 63 61 63 68 65 23 31 00 dd e4 dd 1e c2  l2-cache#1......
        ec d4 ba ce 04 ec cc de 8e 85 e9 ca c4 ec cc 9e  ................
      backtrace:
        [<c02d3350>] kvasprintf+0x64/0xc8
        [<c02d3400>] kasprintf+0x4c/0x5c
        [<c0453814>] safe_name.isra.1+0x80/0xc4
        [<c04545d8>] __of_attach_node_sysfs+0x6c/0x11c
        [<c075f21c>] of_core_init+0x8c/0xf8
        [<c0729594>] kernel_init_freeable+0xd4/0x208
        [<c00047e8>] kernel_init+0x24/0x11c
        [<c00158ec>] ret_from_kernel_thread+0x5c/0x64
    
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331Signed-off-by: default avatarFrank Rowand <frank.rowand@am.sony.com>
    Reported-by: mathieu.malaterre@gmail.com
    Tested-by: default avatarMathieu Malaterre <mathieu.malaterre@gmail.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarRob Herring <robh@kernel.org>
    d9fc8807
base.c 63.3 KB