From patchwork Mon Dec 15 11:14:24 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dmitry pervushin X-Patchwork-Id: 14015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC46DDDFAF for ; Mon, 15 Dec 2008 22:40:32 +1100 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.68 #1 (Red Hat Linux)) id 1LCBmP-0000tV-FF; Mon, 15 Dec 2008 11:38:29 +0000 Received: from mail-ew0-f13.google.com ([209.85.219.13]) by bombadil.infradead.org with esmtp (Exim 4.68 #1 (Red Hat Linux)) id 1LCBPH-0003Q3-AJ for linux-mtd@lists.infradead.org; Mon, 15 Dec 2008 11:14:35 +0000 Received: by mail-ew0-f13.google.com with SMTP id 6so3075767ewy.18 for ; Mon, 15 Dec 2008 03:14:35 -0800 (PST) Received: by 10.210.92.8 with SMTP id p8mr2138827ebb.55.1229339673392; Mon, 15 Dec 2008 03:14:33 -0800 (PST) Received: from ?192.168.66.247? ([62.140.235.235]) by mx.google.com with ESMTPS id d26sm1218426nfh.66.2008.12.15.03.14.32 (version=SSLv3 cipher=RC4-MD5); Mon, 15 Dec 2008 03:14:32 -0800 (PST) Subject: [PATCH] [UBI] 4/5 - allow register null mtd in mtd_blktrans, take two From: dmitry pervushin To: linux-mtd@lists.infradead.org Organization: Home, sweet home... Date: Mon, 15 Dec 2008 14:14:24 +0300 Message-Id: <1229339664.7900.24.camel@hp.diimka.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.22.1.1 X-Spam-Score: 0.0 (/) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.9 Precedence: list Reply-To: dpervushin@gmail.com List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Allow pass NULL as mtd in mtd_blktrans. Also, allow dynamic major number for mtd blktrans block devices. Signed-off-by: dmitry pervushin --- drivers/mtd/mtd_blkdevs.c | 54 +++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) Index: ubifs-2.6/drivers/mtd/mtd_blkdevs.c =================================================================== --- ubifs-2.6.orig/drivers/mtd/mtd_blkdevs.c +++ ubifs-2.6/drivers/mtd/mtd_blkdevs.c @@ -132,6 +132,24 @@ static void mtd_blktrans_request(struct wake_up_process(tr->blkcore_priv->thread); } +static int mtd_blktrans_get(struct mtd_info *mtd) +{ + if (mtd) { + if (!try_module_get(mtd->owner)) + return -ENODEV; + mtd->usecount++; + } + return 0; +} + +static int mtd_blktrans_put(struct mtd_info *mtd) +{ + if (mtd) { + mtd->usecount--; + module_put(mtd->owner); + } + return 0; +} static int blktrans_open(struct block_device *bdev, fmode_t mode) { @@ -139,25 +157,29 @@ static int blktrans_open(struct block_de struct mtd_blktrans_ops *tr = dev->tr; int ret = -ENODEV; - if (!try_module_get(dev->mtd->owner)) - goto out; - - if (!try_module_get(tr->owner)) - goto out_tr; - /* FIXME: Locking. A hot pluggable device can go away (del_mtd_device can be called for it) without its module being unloaded. */ - dev->mtd->usecount++; + if (dev->mtd) + if (!mtd_blktrans_get(dev->mtd)) + goto out; + + if (!try_module_get(tr->owner)) + goto out_tr; ret = 0; - if (tr->open && (ret = tr->open(dev))) { - dev->mtd->usecount--; - module_put(dev->mtd->owner); - out_tr: - module_put(tr->owner); + if (tr->open) { + ret = tr->open(dev); + if (ret) + goto out_all; } - out: + return ret; + +out_all: + module_put(tr->owner); +out_tr: + mtd_blktrans_put(dev->mtd); +out: return ret; } @@ -171,8 +193,7 @@ static int blktrans_release(struct gendi ret = tr->release(dev); if (!ret) { - dev->mtd->usecount--; - module_put(dev->mtd->owner); + mtd_blktrans_put(dev->mtd); module_put(tr->owner); } @@ -354,13 +375,15 @@ int register_mtd_blktrans(struct mtd_blk mutex_lock(&mtd_table_mutex); ret = register_blkdev(tr->major, tr->name); - if (ret) { + if (ret < 0) { printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n", tr->name, tr->major, ret); kfree(tr->blkcore_priv); mutex_unlock(&mtd_table_mutex); return ret; } + if (!tr->major) + tr->major = ret; spin_lock_init(&tr->blkcore_priv->queue_lock); tr->blkcore_priv->rq = blk_init_queue(mtd_blktrans_request, &tr->blkcore_priv->queue_lock);