Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754117Ab0A3PGg (ORCPT ); Sat, 30 Jan 2010 10:06:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753793Ab0A3PGd (ORCPT ); Sat, 30 Jan 2010 10:06:33 -0500 Received: from mail-fx0-f220.google.com ([209.85.220.220]:55839 "EHLO mail-fx0-f220.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753629Ab0A3PDM (ORCPT ); Sat, 30 Jan 2010 10:03:12 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=GR3Htr/1u/OX/30J75bCplyDq9Pqr0CKdP4e8w4lFW+zEE9onpoSMgn7Tu0wUS2cz4 Bdx8uVL/Ux+nhKFwpaBMU0mWEi4vYl69+0UIf7eoytWaO46JNhw72ssALymn/mAKkqoi 7TVM1SfM+NEd0wG9zX042oVP302RGpAxradHs= From: Maxim Levitsky To: David Woodhouse Cc: Artem Bityutskiy , linux-mtd , linux-kernel , Alex Dubov , joern , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 04/17] blktrans: don't free mtd_blktrans_dev, core will do that for you Date: Sat, 30 Jan 2010 17:02:35 +0200 Message-Id: <1264863768-27606-5-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1264863768-27606-1-git-send-email-maximlevitsky@gmail.com> References: <1264863768-27606-1-git-send-email-maximlevitsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4589 Lines: 158 We need that structure till last user exits, and that might be years after mtd device disappered. Signed-off-by: Maxim Levitsky --- drivers/mtd/ftl.c | 1 - drivers/mtd/inftlcore.c | 1 - drivers/mtd/mtd_blkdevs.c | 13 +++++++++++++ drivers/mtd/mtdblock.c | 1 - drivers/mtd/mtdblock_ro.c | 1 - drivers/mtd/nftlcore.c | 1 - drivers/mtd/rfd_ftl.c | 1 - drivers/mtd/ssfdc.c | 1 - include/linux/mtd/blktrans.h | 1 + 9 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index e56d6b4..62da9eb 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -1082,7 +1082,6 @@ static void ftl_remove_dev(struct mtd_blktrans_dev *dev) { del_mtd_blktrans_dev(dev); ftl_freepart((partition_t *)dev); - kfree(dev); } static struct mtd_blktrans_ops ftl_tr = { diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index 8aca552..015a7fe 100755 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c @@ -139,7 +139,6 @@ static void inftl_remove_dev(struct mtd_blktrans_dev *dev) kfree(inftl->PUtable); kfree(inftl->VUtable); - kfree(inftl); } /* diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 966398b..9e118cf 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -131,6 +131,9 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) if (dev->open++) goto out; + if (dev->deleted) + goto out; + if (!try_module_get(tr->owner)) goto out_tr; @@ -169,6 +172,14 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode) module_put(tr->owner); } + /* Free the private data */ + if (dev->deleted) { + module_put(tr->owner); + mutex_unlock(&dev->lock); + kfree(dev); + return 0; + } + return ret; } @@ -338,6 +349,8 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) /* stop new requests to arrive */ del_gendisk(old->disk); + old->deleted = 1; + /* Stop the thread */ kthread_stop(old->thread); diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index 9f41b1a..d8322cc 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -368,7 +368,6 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev) { del_mtd_blktrans_dev(dev); - kfree(dev); } static struct mtd_blktrans_ops mtdblock_tr = { diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c index 852165f..54ff288 100644 --- a/drivers/mtd/mtdblock_ro.c +++ b/drivers/mtd/mtdblock_ro.c @@ -49,7 +49,6 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev) { del_mtd_blktrans_dev(dev); - kfree(dev); } static struct mtd_blktrans_ops mtdblock_tr = { diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index 1002e18..a4578bf 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -126,7 +126,6 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev) del_mtd_blktrans_dev(dev); kfree(nftl->ReplUnitTable); kfree(nftl->EUNtable); - kfree(nftl); } /* diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index d2aa9c4..63b83c0 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -817,7 +817,6 @@ static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev) vfree(part->sector_map); kfree(part->header_cache); kfree(part->blocks); - kfree(part); } static struct mtd_blktrans_ops rfd_ftl_tr = { diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index 3f67e00..81c4ecd 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c @@ -375,7 +375,6 @@ static void ssfdcr_remove_dev(struct mtd_blktrans_dev *dev) del_mtd_blktrans_dev(dev); kfree(ssfdc->logic_block_map); - kfree(ssfdc); } static int ssfdcr_readsect(struct mtd_blktrans_dev *dev, diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h index 507f7b2..e276aca 100644 --- a/include/linux/mtd/blktrans.h +++ b/include/linux/mtd/blktrans.h @@ -24,6 +24,7 @@ struct mtd_blktrans_dev { int devnum; unsigned long size; int readonly; + int deleted; int open; struct gendisk *disk; struct task_struct *thread; -- 1.6.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/