linux/drivers/of
Frank Rowand b4d9416d63 of: fix memory leak related to safe_name()
[ Upstream commit d9fc880723 ]

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=120331

Signed-off-by: Frank Rowand <frank.rowand@am.sony.com>
Reported-by: mathieu.malaterre@gmail.com
Tested-by: Mathieu Malaterre <mathieu.malaterre@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
History 2016-08-22 12:23:00 -04:00
..
testcase-data of: Fix overflow bug in string property parsing functions 2014-11-04 10:19:48 +00:00
address.c of/address: Don't loop forever in of_find_matching_node_by_address(). 2015-10-27 22:14:51 -04:00
base.c of: fix memory leak related to safe_name() 2016-08-22 12:23:00 -04:00
device.c of: rename of_aliases_mutex to just of_mutex 2014-07-07 13:42:52 +01:00
dynamic.c of: fix memory leak related to safe_name() 2016-08-22 12:23:00 -04:00
fdt.c of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap 2014-11-26 12:35:52 +00:00
fdt_address.c of/fdt: add FDT address translation support 2014-05-20 15:19:25 -05:00
irq.c of: irq: fix of_irq_get[_byname]() kernel-doc 2016-06-19 23:47:44 -04:00
Kconfig of/selftest: Use the resolver to fixup phandles 2014-10-04 21:24:35 +01:00
Makefile of: Introduce Device Tree resolve support. 2014-10-04 21:24:26 +01:00
of_mdio.c of_mdio: add new DT property 'managed' to specify the PHY management type 2015-10-27 09:33:12 -04:00
of_mtd.c of_mtd: Add helpers to get ECC strength and ECC step size 2014-03-10 22:42:28 -07:00
of_net.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2014-04-02 20:53:45 -07:00
of_pci.c of/pci: Free resources on failure in of_pci_get_host_bridge_resources() 2015-03-23 21:02:52 -04:00
of_pci_irq.c of_pci_irq: kill useless variable in of_irq_parse_pci() 2014-05-27 12:13:34 +01:00
of_private.h of: fix memory leak related to safe_name() 2016-08-22 12:23:00 -04:00
of_reserved_mem.c of: alloc anywhere from memblock if range not specified 2016-04-18 08:49:23 -04:00
pdt.c of: device_node kobject lifecycle fixes 2014-03-19 14:58:40 +00:00
platform.c of: amba: use of_dma_configure for AMBA devices 2014-09-22 11:26:59 +01:00
resolver.c of: Introduce Device Tree resolve support. 2014-10-04 21:24:26 +01:00
selftest.c of/selftest: Fix testing when /aliases is missing 2014-11-20 15:32:49 +00:00