Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4353819imu; Mon, 24 Dec 2018 23:15:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN58sv08Ys4oB3ggRLljHYhFrE85pRRAxHeJTqtCNciXl88Bi6BvbkjspdEFbg8vH4zjh96s X-Received: by 2002:a17:902:380c:: with SMTP id l12mr15144970plc.326.1545722150232; Mon, 24 Dec 2018 23:15:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545722150; cv=none; d=google.com; s=arc-20160816; b=mGjZafgy/uCh+KYJ1tg1D3QAT7OZm2iVYMxJPjb6PYUHkyGA5tnnqLKzH2s4ntyCxH u3kqv+6EAnG5zrnT5NusZ3lktCwueGUSY+vKNOyvGN8XAav7sfdg21TPXZo2u7JdMPba Pg9VKniUutUYfB4+V/u0Hfhdh1YJGWNr2PIBaMXXEfMlQNTPUhz6Ny/qvdWdOrBzMb5o /TA4KwFq5iFxsBXv2wLNPBN+1LQ003gSG8bIRgTIX2Kyu9CjT1Sb82s+nd3TF631E01e SpJHJPQ3kPQu5y1NC6I7OgDwdwSYjzO6L8pIbVZFX2hV9AsYytY9L/kD2yzzabeUphub jorQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=7++XvzbZa2xx1WKJ+iVHcv7d3EZP/WaugNpkZas4fhw=; b=wYGzVgNouW56SuHBqay95YZ52T8JKiFIK0TPZsz9PtieID3+53epVyasniA5hxztwt Kq2QgiipYMzBgswEOCERRLG7c2xKQRZzmiMrf+afGu/p6bkRkvHS9wJTxdjOZVLWeRfy K0dJmnJIDaEerU0SBe+bF3BURSgRFOupqu8uW7NpxiTBIO5yzFCnHMelpgFNBuW3GMRd 9sfHa6oSXF+avGjaFOlCj1+eZY+jU6Qsf34rD6tq7CPneWrdG2hjmHa72t+07Y7Q57xp bV8GhXq7A0y+DKVXZ/Mhs7BoEealoPtWlpILh645glcgNq27MJnBYHoNGXSkDa+mVhxd gxEQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19si31096324pfi.261.2018.12.24.23.15.35; Mon, 24 Dec 2018 23:15:50 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725847AbeLYHO3 (ORCPT + 99 others); Tue, 25 Dec 2018 02:14:29 -0500 Received: from mail.windriver.com ([147.11.1.11]:50579 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725824AbeLYHO2 (ORCPT ); Tue, 25 Dec 2018 02:14:28 -0500 Received: from ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) by mail.windriver.com (8.15.2/8.15.1) with ESMTPS id wBP7EEuq016203 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 24 Dec 2018 23:14:14 -0800 (PST) Received: from pek-lpggp3.wrs.com (128.224.153.76) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.408.0; Mon, 24 Dec 2018 23:14:14 -0800 From: Liwei Song To: Boris , Mauro CC: , , Subject: [PATCH] edac: unregister the mci device before free the mci memory Date: Tue, 25 Dec 2018 02:13:04 -0500 Message-ID: <1545721984-183750-1-git-send-email-liwei.song@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(); 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. 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); } static const struct device_type mci_attr_type = { -- 2.7.4