Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:36057 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753170Ab3JHCUK (ORCPT ); Mon, 7 Oct 2013 22:20:10 -0400 Date: Mon, 7 Oct 2013 19:13:04 -0700 From: Greg Kroah-Hartman To: Larry Finger Cc: linville@tuxdriver.com, Alex Dubov , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Kay Sievers Subject: Re: [PATCH V2] memstick: Fix memory leak in memstick_check() error path Message-ID: <20131008021304.GB32733@kroah.com> (sfid-20131008_042027_503797_F89EACA7) References: <1380834798-5829-1-git-send-email-Larry.Finger@lwfinger.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <1380834798-5829-1-git-send-email-Larry.Finger@lwfinger.net> Sender: linux-wireless-owner@vger.kernel.org List-ID: On Sun, Oct 06, 2013 at 10:21:51PM -0500, Larry Finger wrote: > With kernel 3.12-rc3, kmemleak reports the following leak: > > > unreferenced object 0xffff8800ae85c190 (size 16): > > comm "kworker/u4:3", pid 685, jiffies 4294916336 (age 2831.760s) > > hex dump (first 16 bytes): > > 6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00 memstick0....... > > backtrace: > > [] kmemleak_alloc+0x21/0x50 > > [] __kmalloc_track_caller+0x160/0x2f0 > > [] kvasprintf+0x5b/0x90 > > [] kobject_set_name_vargs+0x21/0x60 > > [] dev_set_name+0x3c/0x40 > > [] memstick_check+0xb8/0x340 [memstick] > > [] process_one_work+0x1d2/0x670 > > [] worker_thread+0x11a/0x370 > > [] kthread+0xd6/0xe0 > > [] ret_from_fork+0x7c/0xb0 > > This problem was introduced by commit 0252c3b "memstick: struct device - > replace bus_id with dev_name(), dev_set_name()" where the name is not freed > in the error path. The name is also leaked in memstick_free_card(). > > Thanks to Catalin Marinas for suggesting the fix. > > Cc: Kay Sievers > Cc: Alex Dubov > Cc: Greg Kroah-Hartman > Signed-off-by: Larry Finger > --- > > V2 fixes the typos in the commit message, and frees the name in > memstick_free_card() as well as the error path in memstick_check(). Looking back at this, to try to figure out why the kmemleak report shows up, shows that this is a mess. Why would we be erroring out _before_ we try to register the struct device with the driver core, yet we had already initialized the struct device structure? Only set up the structure right before sending it to driver core, don't delay in allocation, only problems can happen (like here.) To fix this up, will take some major work, which I can't do, sorry, but this patch will not work either. greg k-h