From patchwork Wed Jan 6 07:22:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7965021 Return-Path: X-Original-To: patchwork-linux-block@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 3CD0D9FCC4 for ; Wed, 6 Jan 2016 07:23:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E456201C7 for ; Wed, 6 Jan 2016 07:23:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1303B201C0 for ; Wed, 6 Jan 2016 07:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752011AbcAFHXX (ORCPT ); Wed, 6 Jan 2016 02:23:23 -0500 Received: from mga02.intel.com ([134.134.136.20]:14879 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbcAFHXX (ORCPT ); Wed, 6 Jan 2016 02:23:23 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 05 Jan 2016 23:23:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,528,1444719600"; d="scan'208";a="721101841" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.136]) by orsmga003.jf.intel.com with ESMTP; 05 Jan 2016 23:23:23 -0800 Subject: [PATCH 2/9] block: clarify badblocks lifetime From: Dan Williams To: linux-nvdimm@lists.01.org Cc: linux-block@vger.kernel.org, vishal.l.verma@intel.com, x86@kernel.org Date: Tue, 05 Jan 2016 23:22:57 -0800 Message-ID: <20160106072257.40900.58682.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20160106072246.40900.8851.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20160106072246.40900.8851.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 | 10 +++++++--- 3 files changed, 9 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/badblocks.c b/block/badblocks.c index 96aeb9194a2e..9be8bf94f979 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -555,6 +555,8 @@ EXPORT_SYMBOL_GPL(badblocks_init); */ void badblocks_free(struct badblocks *bb) { + if (!bb) + return; kfree(bb->page); bb->page = NULL; } diff --git a/block/genhd.c b/block/genhd.c index 5481b5308a70..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_free(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..dd829251342d 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,14 @@ 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_free(disk->bb); + del_gendisk_queue(disk); + put_disk(disk); } static int pmem_attach_disk(struct device *dev,