From patchwork Wed Jan 6 22:31:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7971511 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 21FC69F744 for ; Wed, 6 Jan 2016 22:31:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4795B2015E for ; Wed, 6 Jan 2016 22:31:36 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DF6420142 for ; Wed, 6 Jan 2016 22:31:35 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 639511A210A; Wed, 6 Jan 2016 14:31:35 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id BCA2F1A210A for ; Wed, 6 Jan 2016 14:31:33 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 06 Jan 2016 14:31:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,530,1444719600"; d="scan'208";a="875979555" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.136]) by fmsmga001.fm.intel.com with ESMTP; 06 Jan 2016 14:31:33 -0800 Subject: [PATCH v2 3/9] block: clarify badblocks lifetime From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 06 Jan 2016 14:31:07 -0800 Message-ID: <20160106223107.2736.91985.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20160106223051.2736.43057.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20160106223051.2736.43057.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Cc: linux-block@vger.kernel.org X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The badblocks list attached to a gendisk is optionally allocated by the driver which implies the driver owns the lifetime of the object. Do not automatically free it in del_gendisk(), leave that to the driver. This is in preparation for expanding the use of badblocks in libnvdimm drivers and introducing devm_alloc_badblocks(). Signed-off-by: Dan Williams --- block/badblocks.c | 2 ++ block/genhd.c | 5 ----- drivers/nvdimm/pmem.c | 11 ++++++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index fabf6b64c2d1..37e5c0a2ef69 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -555,6 +555,8 @@ EXPORT_SYMBOL_GPL(badblocks_init); */ void badblocks_exit(struct badblocks *bb) { + if (!bb) + return; kfree(bb->page); bb->page = NULL; } diff --git a/block/genhd.c b/block/genhd.c index 5e78f6eec8dd..b96012849e26 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -660,11 +660,6 @@ static void del_gendisk_end(struct gendisk *disk) blk_unregister_queue(disk); blk_unregister_region(disk_devt(disk), disk->minors); - if (disk->bb) { - badblocks_exit(disk->bb); - kfree(disk->bb); - } - part_stat_set_all(&disk->part0, 0); disk->part0.stamp = 0; diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index d20c8112e90d..8f562acc5034 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -155,11 +156,15 @@ static struct pmem_device *pmem_alloc(struct device *dev, static void pmem_detach_disk(struct pmem_device *pmem) { - if (!pmem->pmem_disk) + struct gendisk *disk = pmem->pmem_disk; + + if (!disk) return; - del_gendisk_queue(pmem->pmem_disk); - put_disk(pmem->pmem_disk); + badblocks_exit(disk->bb); + kfree(disk->bb); + del_gendisk_queue(disk); + put_disk(disk); } static int pmem_attach_disk(struct device *dev,