aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Corbet <corbet@lwn.net>2008-05-15 12:10:37 -0400
committerJonathan Corbet <corbet@lwn.net>2008-06-20 16:03:43 -0400
commit6071239ef1947914892601e36785c7b1cf8b7dd4 (patch)
treee7e2a6718ab3e97590c670262a746f042157e756
parentea2959a2972410f15155a015df74ce77ac79f8b8 (diff)
mtdchar: cdev lock_kernel() pushdown
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r--drivers/mtd/mtdchar.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5d3ac512ce16..129d429cd2da 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/smp_lock.h>
17 18
18#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
19#include <linux/mtd/compatmac.h> 20#include <linux/mtd/compatmac.h>
@@ -86,6 +87,7 @@ static int mtd_open(struct inode *inode, struct file *file)
86{ 87{
87 int minor = iminor(inode); 88 int minor = iminor(inode);
88 int devnum = minor >> 1; 89 int devnum = minor >> 1;
90 int ret = 0;
89 struct mtd_info *mtd; 91 struct mtd_info *mtd;
90 struct mtd_file_info *mfi; 92 struct mtd_file_info *mfi;
91 93
@@ -98,31 +100,39 @@ static int mtd_open(struct inode *inode, struct file *file)
98 if ((file->f_mode & 2) && (minor & 1)) 100 if ((file->f_mode & 2) && (minor & 1))
99 return -EACCES; 101 return -EACCES;
100 102
103 lock_kernel();
101 mtd = get_mtd_device(NULL, devnum); 104 mtd = get_mtd_device(NULL, devnum);
102 105
103 if (IS_ERR(mtd)) 106 if (IS_ERR(mtd)) {
104 return PTR_ERR(mtd); 107 ret = PTR_ERR(mtd);
108 goto out;
109 }
105 110
106 if (MTD_ABSENT == mtd->type) { 111 if (MTD_ABSENT == mtd->type) {
107 put_mtd_device(mtd); 112 put_mtd_device(mtd);
108 return -ENODEV; 113 ret = -ENODEV;
114 goto out;
109 } 115 }
110 116
111 /* You can't open it RW if it's not a writeable device */ 117 /* You can't open it RW if it's not a writeable device */
112 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { 118 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
113 put_mtd_device(mtd); 119 put_mtd_device(mtd);
114 return -EACCES; 120 ret = -EACCES;
121 goto out;
115 } 122 }
116 123
117 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); 124 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
118 if (!mfi) { 125 if (!mfi) {
119 put_mtd_device(mtd); 126 put_mtd_device(mtd);
120 return -ENOMEM; 127 ret = -ENOMEM;
128 goto out;
121 } 129 }
122 mfi->mtd = mtd; 130 mfi->mtd = mtd;
123 file->private_data = mfi; 131 file->private_data = mfi;
124 132
125 return 0; 133out:
134 unlock_kernel();
135 return ret;
126} /* mtd_open */ 136} /* mtd_open */
127 137
128/*====================================================================*/ 138/*====================================================================*/