From patchwork Wed Feb 17 21:49:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 45683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.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 11E14B7D05 for ; Thu, 18 Feb 2010 08:52:50 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NhrmD-0005Q9-FR; Wed, 17 Feb 2010 21:49:45 +0000 Received: from fg-out-1718.google.com ([72.14.220.152]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1Nhrm4-0005Fx-A2 for linux-mtd@lists.infradead.org; Wed, 17 Feb 2010 21:49:43 +0000 Received: by fg-out-1718.google.com with SMTP id e21so180865fga.0 for ; Wed, 17 Feb 2010 13:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=Quqj17O1o0/SkO0XAnOE1mqSqIumqRvece2xKR7L1pI=; b=OEMvJbZiScPghcUkE9vgYnT61zejEhH56Ns4oPzm09WMOyBG+I2jzFhz+G/0AIH23D huR3uJy5WQlu57U6M9GbzrNg9/1SgM5b9hbUjLpUaTlX8+I5M2MOHSw+6CuqJ7ywo5M9 rHkDGGthxCo9vMX17o5hjyRSwrCUR0XaIDjxU= 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=vxe7V3Rvz4hE+U+LFjeZZ+Bidpemby5Z/x0wgR8akNZlPF6w0wEV8sHlQ64IswTLW6 4cklivV/IWhv9V7bvwhRC2FiEPdbCI/OCR8d2a0kbTmcrnApsH845HUv7K05EB6Gn9/k mFsfhOcvFPIvKdSv52HjCSWU04uKCxQimWO5o= Received: by 10.87.48.11 with SMTP id a11mr15405148fgk.36.1266443373899; Wed, 17 Feb 2010 13:49:33 -0800 (PST) Received: from localhost.localdomain ([77.126.218.27]) by mx.google.com with ESMTPS id d4sm3096749fga.8.2010.02.17.13.49.32 (version=SSLv3 cipher=RC4-MD5); Wed, 17 Feb 2010 13:49:33 -0800 (PST) From: Maxim Levitsky To: David Woodhouse Subject: [PATCH 01/14] MTD: create unlocked versions of {get, put}_mtd_device Date: Wed, 17 Feb 2010 23:49:11 +0200 Message-Id: <1266443364-4538-2-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1266443364-4538-1-git-send-email-maximlevitsky@gmail.com> References: <1266443364-4538-1-git-send-email-maximlevitsky@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100217_164936_504806_25FB2B29 X-CRM114-Status: GOOD ( 16.31 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- _SUMMARY_ Cc: Maxim Levitsky , Alex Dubov , Artem Bityutskiy , joern , Vitaly Wool , linux-kernel , "stanley.miao" , linux-mtd , Thomas Gleixner X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use these only if you know that you already hold mtd_table_mutex Signed-off-by: Maxim Levitsky --- drivers/mtd/mtdcore.c | 60 ++++++++++++++++++++++++++++++---------------- include/linux/mtd/mtd.h | 3 +- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c356c0a..3bdb7e8 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -453,27 +453,38 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) ret = NULL; } - if (!ret) - goto out_unlock; - - if (!try_module_get(ret->owner)) - goto out_unlock; - - if (ret->get_device) { - err = ret->get_device(ret); - if (err) - goto out_put; + if (!ret) { + ret = ERR_PTR(err); + goto out; } - ret->usecount++; + err = __get_mtd_device(ret); + if (err) + ret = ERR_PTR(err); +out: mutex_unlock(&mtd_table_mutex); return ret; +} -out_put: - module_put(ret->owner); -out_unlock: - mutex_unlock(&mtd_table_mutex); - return ERR_PTR(err); + +int __get_mtd_device(struct mtd_info *mtd) +{ + int err; + + if (!try_module_get(mtd->owner)) + return -ENODEV; + + if (mtd->get_device) { + + err = mtd->get_device(mtd); + + if (err) { + module_put(mtd->owner); + return err; + } + } + mtd->usecount++; + return 0; } /** @@ -524,14 +535,19 @@ out_unlock: void put_mtd_device(struct mtd_info *mtd) { - int c; - mutex_lock(&mtd_table_mutex); - c = --mtd->usecount; + __put_mtd_device(mtd); + mutex_unlock(&mtd_table_mutex); + +} + +void __put_mtd_device(struct mtd_info *mtd) +{ + --mtd->usecount; + BUG_ON(mtd->usecount < 0); + if (mtd->put_device) mtd->put_device(mtd); - mutex_unlock(&mtd_table_mutex); - BUG_ON(c < 0); module_put(mtd->owner); } @@ -569,7 +585,9 @@ EXPORT_SYMBOL_GPL(add_mtd_device); EXPORT_SYMBOL_GPL(del_mtd_device); EXPORT_SYMBOL_GPL(get_mtd_device); EXPORT_SYMBOL_GPL(get_mtd_device_nm); +EXPORT_SYMBOL_GPL(__get_mtd_device); EXPORT_SYMBOL_GPL(put_mtd_device); +EXPORT_SYMBOL_GPL(__put_mtd_device); EXPORT_SYMBOL_GPL(register_mtd_user); EXPORT_SYMBOL_GPL(unregister_mtd_user); EXPORT_SYMBOL_GPL(default_mtd_writev); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 0f32a9b..662d747 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -290,8 +290,9 @@ extern int add_mtd_device(struct mtd_info *mtd); extern int del_mtd_device (struct mtd_info *mtd); extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); +extern int __get_mtd_device(struct mtd_info *mtd); +extern void __put_mtd_device(struct mtd_info *mtd); extern struct mtd_info *get_mtd_device_nm(const char *name); - extern void put_mtd_device(struct mtd_info *mtd);