From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-x244.google.com (mail-pa0-x244.google.com [IPv6:2607:f8b0:400e:c03::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rVJD96HjMzDql8 for ; Thu, 16 Jun 2016 06:35:05 +1000 (AEST) Received: by mail-pa0-x244.google.com with SMTP id us13so2138888pab.1 for ; Wed, 15 Jun 2016 13:35:05 -0700 (PDT) Subject: Re: [PATCH] of: fix memory leak related to safe_name() To: Rob Herring References: <57619AE5.70102@gmail.com> Cc: Mathieu Malaterre , "devicetree@vger.kernel.org" , linuxppc-dev , "linux-kernel@vger.kernel.org" From: Frank Rowand Message-ID: <5761BBF1.2010604@gmail.com> Date: Wed, 15 Jun 2016 13:34:57 -0700 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 06/15/16 12:12, Rob Herring wrote: > On Wed, Jun 15, 2016 at 1:13 PM, Frank Rowand wrote: >> From: Frank Rowand >> >> 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: >> [] kvasprintf+0x64/0xc8 >> [] kasprintf+0x4c/0x5c >> [] safe_name.isra.1+0x80/0xc4 >> [] __of_attach_node_sysfs+0x6c/0x11c >> [] of_core_init+0x8c/0xf8 >> [] kernel_init_freeable+0xd4/0x208 >> [] kernel_init+0x24/0x11c >> [] ret_from_kernel_thread+0x5c/0x64 >> >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=120331 >> >> Signed-off-by: Frank Rowand >> Reported-by: mathieu.malaterre@gmail.com > > [...] > >> Index: b/include/linux/of.h >> =================================================================== >> --- a/include/linux/of.h >> +++ b/include/linux/of.h >> @@ -121,6 +121,8 @@ static inline int of_node_is_attached(st >> #ifdef CONFIG_OF_DYNAMIC >> extern struct device_node *of_node_get(struct device_node *node); >> extern void of_node_put(struct device_node *node); >> +extern void __of_sysfs_remove_bin_file(struct device_node *np, >> + struct property *prop); > > Should be internal to DT code, right?Yes. Yes, thanks. v2 on the way, moved prototype to of_private.h > >> #else /* CONFIG_OF_DYNAMIC */ >> /* Dummy ref counting routines - to be implemented later */ >> static inline struct device_node *of_node_get(struct device_node *node) >