Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1740172imu; Thu, 10 Jan 2019 02:08:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN7KDPPRwupD5O+GqiFvKNMQEtqWcqe+QD2M3eYnCR9UJ9CIn6Py9mSZNTYysIxs+EdQ0/A/ X-Received: by 2002:a63:f615:: with SMTP id m21mr8998993pgh.428.1547114916880; Thu, 10 Jan 2019 02:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547114916; cv=none; d=google.com; s=arc-20160816; b=cs7q+JJuaZsp5IFXz468DmJYVulCr6BcfkDDP+/qSEQ12I9iIV0KDpei+HKL5fVORF OtqLXxGnrupiWkPI+FyWztyOhflj0n9VtRTTgnR0QluvKH3tklluivbn8Kt3nPWm72aj JQYohGHZZTAFpp1t1KHgfzgJmQVPndM36W7PwpOqtyD9L/J8hOV9V9T6PhFSB5lOx8ar bmsl+sJFbAa2c30DOfz722g9djS8Ady9/Bh7fesshVJjSRXGS+CW/4x+VI61QdZjLVEn kcyYacoJ9Hp//G85UItNohPvgl0tQp0CIGOPCT9zh2AdSxuilg/Kdg8c4qgiKz8f256/ 5CCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=avkZMy8iTqCYsOP/GBrvrkJxLCKAdcWdpaJY93QfGqw=; b=zEJPs/oVfptJhxhBVQVQprMHbYxpOAPnUPDYMWyP4+hNB5Yd9G92hbtJACN1IePB1q HKoAt/I3Rzas1EkoHSpuMfx9oyqjumLxyqci5pEVZcN4SxHn3b+VXOtd9IMrCSBxDS2B TMTGdv6sI28tEt1F6hy6zK9qrv7yA7C22qmO/K9XptBYQOW6C0uHBMO97+cKdBwR0UqU awiTP37SCwLyXABX2AouZZ8re9RNLW6g/LUOCi6ECXEIi1IHhDmUJ5tjpXtjfMJpyrbH OCotujcARAt4YmYlsBCFaS3OlA75wwpbYFEBISfsRDQSfr0f8zhgUNAqUXEcROOtD1B8 6Hhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=cJvYz2cF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z38si5378679pga.193.2019.01.10.02.08.20; Thu, 10 Jan 2019 02:08:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=cJvYz2cF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727745AbfAJJKn (ORCPT + 99 others); Thu, 10 Jan 2019 04:10:43 -0500 Received: from mail.skyhub.de ([5.9.137.197]:45840 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727220AbfAJJKm (ORCPT ); Thu, 10 Jan 2019 04:10:42 -0500 Received: from zn.tnic (p200300EC2BC5CF005460B1C1902C795E.dip0.t-ipconnect.de [IPv6:2003:ec:2bc5:cf00:5460:b1c1:902c:795e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 84A021EC0432; Thu, 10 Jan 2019 10:10:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1547111440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=avkZMy8iTqCYsOP/GBrvrkJxLCKAdcWdpaJY93QfGqw=; b=cJvYz2cFf0BxRqMEpVCBujk2YoW6iI+hnEhO2n89CBUsrB6Sya2ddhSkiETe/cylv3put0 srjclBTpP8uVYNhCIL/IzrLfe/ovfx17RTVz8gHPU6cUis6qg75KyFK/zXOWQNecsr8HuF 9vnL62VOTOVgKoA2YU/r8ZUdUYdCMh0= Date: Thu, 10 Jan 2019 10:10:31 +0100 From: Borislav Petkov To: Liwei Song Cc: Mauro , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] edac: unregister the mci device before free the mci memory Message-ID: <20190110091031.GA17621@zn.tnic> References: <1545721984-183750-1-git-send-email-liwei.song@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1545721984-183750-1-git-send-email-liwei.song@windriver.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 25, 2018 at 02:13:04AM -0500, Liwei Song wrote: > this patch can fix the following kmemleak: > > unreferenced object 0xffff881022b60ee0 (size 32): > comm "udevd", pid 262, jiffies 4294709066 (age 1410.265s) > hex dump (first 32 bytes): > 00 7c e8 18 10 88 ff ff 00 74 e8 18 10 88 ff ff .|.......t...... > 00 70 e8 18 10 88 ff ff 00 00 00 00 00 00 00 00 .p.............. > backtrace: > [] kmemleak_alloc+0x26/0x50 > [] __kmalloc+0x154/0x2f0 > [] edac_mc_alloc+0x278/0x6d0 > [] 0xffffffffa0106f9d > [] local_pci_probe+0x3e/0x70 > [] pci_device_probe+0x121/0x130 > [] driver_probe_device+0x105/0x260 > [] __driver_attach+0x93/0xa0 > [] bus_for_each_dev+0x63/0xa0 > [] driver_attach+0x1e/0x20 > [] bus_add_driver+0x1f0/0x290 > [] driver_register+0x64/0xf0 > [] __pci_register_driver+0x4c/0x50 > [] 0xffffffffa010d050 > [] do_one_initcall+0x102/0x160 > [] load_module+0x1a65/0x2230 > > The kmemleak happened when run "rmmod sb_edac.ko". > In edac_mc_free, only after mci device is ungistered, it will do the mci > free task, or it will do the mci unregister action, adjust the sequence > of the free task to ungister the device first and then free the mci > struct, then all memory allocated(Include dimms, csrows, channels)by > edac_mc_alloc() will got freed by edac_mc_free(); I'm reading and rereading that "sentence" and still have no clue what it is trying to say. Maybe because it needs to be split into clear and simple declarative sentences explaining what the problem is first, then what happens and then what the proposed solution is. All in simple declarative sentences. Also, spellcheck your writing - there's no "ungister". > Because all allocated memory was freed by edac_mc_free() and the release > hook in edac_mc_sysfs.c can not release all allocated memory of EDAC MC, > so remove the free fragment from it to aviod duplicated memory free. What duplicated memory freeing - above says "unreferenced object" which looks to me like it didn't get freed at all. > Signed-off-by: Liwei Song > --- > drivers/edac/edac_mc.c | 7 ++++--- > drivers/edac/edac_mc_sysfs.c | 12 ------------ > 2 files changed, 4 insertions(+), 15 deletions(-) > > diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c > index 7d3edd713932..12d9dc9cf85e 100644 > --- a/drivers/edac/edac_mc.c > +++ b/drivers/edac/edac_mc.c > @@ -506,6 +506,10 @@ void edac_mc_free(struct mem_ctl_info *mci) > { > edac_dbg(1, "\n"); > > + /* the mci instance is freed here, when the sysfs object is dropped */ > + if (device_is_registered(&mci->dev)) > + edac_unregister_sysfs(mci); > + > /* If we're not yet registered with sysfs free only what was allocated > * in edac_mc_alloc(). > */ > @@ -513,9 +517,6 @@ void edac_mc_free(struct mem_ctl_info *mci) > _edac_mc_free(mci); > return; > } > - > - /* the mci instance is freed here, when the sysfs object is dropped */ > - edac_unregister_sysfs(mci); > } > EXPORT_SYMBOL_GPL(edac_mc_free); > > diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c > index 20374b8248f0..20211b4ee2f1 100644 > --- a/drivers/edac/edac_mc_sysfs.c > +++ b/drivers/edac/edac_mc_sysfs.c > @@ -276,10 +276,6 @@ static const struct attribute_group *csrow_attr_groups[] = { > > static void csrow_attr_release(struct device *dev) > { > - struct csrow_info *csrow = container_of(dev, struct csrow_info, dev); > - > - edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); > - kfree(csrow); > } > > static const struct device_type csrow_attr_type = { > @@ -616,10 +612,6 @@ static const struct attribute_group *dimm_attr_groups[] = { > > static void dimm_attr_release(struct device *dev) > { > - struct dimm_info *dimm = container_of(dev, struct dimm_info, dev); > - > - edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev)); > - kfree(dimm); > } > > static const struct device_type dimm_attr_type = { > @@ -892,10 +884,6 @@ static const struct attribute_group *mci_attr_groups[] = { > > static void mci_attr_release(struct device *dev) > { > - struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); > - > - edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); > - kfree(mci); > } And those functions will become empty? This all looks strange to me. Please try again. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.