From patchwork Thu Oct 15 20:28:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 36148 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 53A04B7B90 for ; Fri, 16 Oct 2009 07:32:30 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MyWwZ-00025v-FV; Thu, 15 Oct 2009 20:29:03 +0000 Received: from www.tglx.de ([62.245.132.106]) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1MyWwS-0001SC-3S; Thu, 15 Oct 2009 20:29:01 +0000 Received: from localhost.localdomain (www.tglx.de [127.0.0.1]) by www.tglx.de (8.13.8/8.13.8/TGLX-2007100201) with ESMTP id n9FKSmkJ016237; Thu, 15 Oct 2009 22:28:48 +0200 Message-Id: <20091015202758.523050101@linutronix.de> User-Agent: quilt/0.47-1 Date: Thu, 15 Oct 2009 20:28:48 -0000 From: Thomas Gleixner To: LKML Subject: [patch 4/5] mtd: Remove BKL and convert to unlocked_ioctl References: <20091015202722.372890083@linutronix.de> Content-Disposition: inline; filename=mtd-remove-bkl-and-convert-to-unlocked-ioctl.patch X-Virus-Scanned: clamav-milter 0.95.1 at www.tglx.de X-Virus-Status: Clean X-Spam-Status: No, score=-1.7 required=5.0 tests=ALL_TRUSTED,AWL autolearn=failed version=3.2.4 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on www.tglx.de X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20091015_162856_362313_5D8F2D99 X-CRM114-Status: GOOD ( 12.50 ) 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: linux-mtd@lists.infradead.org, David Woodhouse , Arnd Bergmann , ALan Cox 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 mtd_open() got lock/unlock kernel from the big BKL push down, but it never relied on the BKL serialization as get_mtd_device() takes care of serialization vs. device init/teardown. mtd_ioctl() is safe w/o the BKL as well. The data which is copied from the mtd data structure is either set up during device initialization or statistics which have never been protected by the BKL against concurrent modification. The mtd functions which are called from various ioctl commands are safe as well. Signed-off-by: Thomas Gleixner Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- drivers/mtd/mtdchar.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) Index: linux-2.6-tip/drivers/mtd/mtdchar.c =================================================================== --- linux-2.6-tip.orig/drivers/mtd/mtdchar.c +++ linux-2.6-tip/drivers/mtd/mtdchar.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -74,18 +73,14 @@ static int mtd_open(struct inode *inode, if ((file->f_mode & FMODE_WRITE) && (minor & 1)) return -EACCES; - lock_kernel(); mtd = get_mtd_device(NULL, devnum); - if (IS_ERR(mtd)) { - ret = PTR_ERR(mtd); - goto out; - } + if (IS_ERR(mtd)) + return PTR_ERR(mtd); if (mtd->type == MTD_ABSENT) { put_mtd_device(mtd); - ret = -ENODEV; - goto out; + return -ENODEV; } if (mtd->backing_dev_info) @@ -94,21 +89,17 @@ static int mtd_open(struct inode *inode, /* You can't open it RW if it's not a writeable device */ if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { put_mtd_device(mtd); - ret = -EACCES; - goto out; + return -EACCES; } mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); if (!mfi) { put_mtd_device(mtd); - ret = -ENOMEM; - goto out; + return -ENOMEM; } mfi->mtd = mtd; file->private_data = mfi; -out: - unlock_kernel(); return ret; } /* mtd_open */ @@ -450,13 +441,12 @@ static int mtd_do_readoob(struct mtd_inf return ret; } -static int mtd_ioctl(struct inode *inode, struct file *file, - u_int cmd, u_long arg) +static long mtd_ioctl(struct file *file, u_int cmd, u_long arg) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; void __user *argp = (void __user *)arg; - int ret = 0; + long ret = 0; u_long size; struct mtd_info_user info; @@ -842,8 +832,6 @@ static long mtd_compat_ioctl(struct file void __user *argp = compat_ptr(arg); int ret = 0; - lock_kernel(); - switch (cmd) { case MEMWRITEOOB32: { @@ -877,8 +865,6 @@ static long mtd_compat_ioctl(struct file ret = mtd_ioctl(inode, file, cmd, (unsigned long)argp); } - unlock_kernel(); - return ret; } @@ -942,7 +928,7 @@ static const struct file_operations mtd_ .llseek = mtd_lseek, .read = mtd_read, .write = mtd_write, - .ioctl = mtd_ioctl, + .unlocked_ioctl = mtd_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = mtd_compat_ioctl, #endif