From patchwork Wed Jan 6 21:45:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 42332 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 14EC8B6F05 for ; Thu, 7 Jan 2010 08:48:02 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NSdhW-0000d1-1M; Wed, 06 Jan 2010 21:45:58 +0000 Received: from mail-fx0-f222.google.com ([209.85.220.222]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NSdhP-0000UU-W4 for linux-mtd@lists.infradead.org; Wed, 06 Jan 2010 21:45:56 +0000 Received: by fxm22 with SMTP id 22so20325031fxm.2 for ; Wed, 06 Jan 2010 13:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=pT+n2UtayIaUUr9rFdLb0XCBIgo7bY4pan9lHKAELCA=; b=NL8gG9Lj0JpDLUoeA4w7P8TYlJaedE/DkBb/BroAx4X0OpaLfLKK4YiqOi6ZgYBZe3 w6PH8wIKZ7NIWvxCTF3mS7r+UfSPTS1h4mB8UE8taJ1GEaEm1S+O3FbOIJgElkbKf0+b oVbhwATJ27RnxGYPDtaW8mMBCW1yuFsUZXgG4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=wB6RPRtJ34mRj/IzooxF1gWkwt862zrxiOEI+J/Q5IZvlAol+diqSHY5zCwMhrNTbE PWfn75ZyZO7ljOEJ0f5lKgrbUhnd0A7pNAmjGiAAOg6G0NzF7ZFUM4e++HULDt4uNnuI IoDJCSeEgzuTG+jsk1kmFxvnySKIW4frOBrio= Received: by 10.223.2.139 with SMTP id 11mr2058707faj.35.1262814351196; Wed, 06 Jan 2010 13:45:51 -0800 (PST) Received: from ?10.1.0.2? (IGLD-84-228-118-133.inter.net.il [84.228.118.133]) by mx.google.com with ESMTPS id 19sm26013081fkr.18.2010.01.06.13.45.49 (version=SSLv3 cipher=RC4-MD5); Wed, 06 Jan 2010 13:45:50 -0800 (PST) Subject: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device From: Maxim Levitsky To: linux-kernel In-Reply-To: <1262814216.14552.22.camel@maxim-laptop> References: <1262814216.14552.22.camel@maxim-laptop> Date: Wed, 06 Jan 2010 23:45:48 +0200 Message-ID: <1262814348.14552.24.camel@maxim-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100106_164552_147025_4E27EC72 X-CRM114-Status: GOOD ( 16.06 ) 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: joern , linux-mtd , Alex Dubov 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: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org >From 10333e0ed6dc7b176f2dfce04f08572f9e1b04ce Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Tue, 5 Jan 2010 22:29:31 +0200 Subject: [PATCH 2/9] MTD: create lockless versions of {get,put}_mtd_device This will be used to resolve deadlock in block translation layer --- drivers/mtd/mtdcore.c | 55 +++++++++++++++++++++++++++------------------- include/linux/mtd/mtd.h | 3 +- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 738e329..e9daf87 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -454,27 +454,30 @@ 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 || (err = __get_mtd_device(ret))) + ret = ERR_PTR(err); - ret->usecount++; 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) { + + if ((err = mtd->get_device(mtd))) { + module_put(mtd->owner); + return err; + } + } + mtd->usecount++; + return 0; } /** @@ -525,18 +528,22 @@ out_unlock: void put_mtd_device(struct mtd_info *mtd) { - int c; - mutex_lock(&mtd_table_mutex); - c = --mtd->usecount; - if (mtd->put_device) - mtd->put_device(mtd); + __put_mtd_device(mtd); mutex_unlock(&mtd_table_mutex); - BUG_ON(c < 0); module_put(mtd->owner); } +void __put_mtd_device(struct mtd_info *mtd) +{ + --mtd->usecount; + BUG_ON(mtd->usecount < 0); + + if (mtd->put_device) + mtd->put_device(mtd); +} + /* default_mtd_writev - default mtd writev method for MTD devices that * don't implement their own */ @@ -570,7 +577,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);