From patchwork Sat Feb 13 13:03:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 45243 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 2F9A0B7C98 for ; Sun, 14 Feb 2010 00:06:36 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NgHeu-0001gU-LP; Sat, 13 Feb 2010 13:03:40 +0000 Received: from mail-fx0-f223.google.com ([209.85.220.223]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NgHei-0001cN-1F for linux-mtd@lists.infradead.org; Sat, 13 Feb 2010 13:03:33 +0000 Received: by fxm23 with SMTP id 23so3374239fxm.2 for ; Sat, 13 Feb 2010 05:03:26 -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=UoX+hbN6cCDEy9eYDksBSp+7okzEqEmu+yz3WzsGFbA=; b=WU1tR/cDVXysYteYx+qNfR7oGQat7tB3y5j6Qn82AK9hF994iJv+cGm4TZLryaf0gm dwxetyHttzjsnmZ/MdBSnm++rcGpDfGmrVCoXncfPsTY0dmwdZbw64n/jlt2xwWiHHWw AytOM3XMEdVhI2y1qvDQBm1Y2nugZDP9lyjQM= 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=SwLvZd7wGi938Us455bGUvilIQmR9vHxQnqFnZVi8RZ1LuBAxNVs9J30lV2a7pYzyh IXfkfUip9qbyoWUnpoFTyTCcKR1TKZvlHCNsYfWd2sHiiVRm6JizbQGnBz3ahj0QYIWk cEAVrhFtYP1WYDrkbxLMLc4kYnhq8Q4eWERlM= Received: by 10.223.16.216 with SMTP id p24mr3064845faa.66.1266066206182; Sat, 13 Feb 2010 05:03:26 -0800 (PST) Received: from localhost.localdomain (87.68.247.153.adsl.012.net.il [87.68.247.153]) by mx.google.com with ESMTPS id 16sm2205430fxm.0.2010.02.13.05.03.24 (version=SSLv3 cipher=RC4-MD5); Sat, 13 Feb 2010 05:03:25 -0800 (PST) From: Maxim Levitsky To: David Woodhouse Subject: [PATCH 01/14] MTD: create unlocked versions of {get, put}_mtd_device Use these only if you know that you already hold mtd_table_mutex Date: Sat, 13 Feb 2010 15:03:00 +0200 Message-Id: <1266066193-17625-2-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1266066193-17625-1-git-send-email-maximlevitsky@gmail.com> References: <1266066193-17625-1-git-send-email-maximlevitsky@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100213_080328_192077_74CF51E6 X-CRM114-Status: GOOD ( 14.17 ) 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 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);