aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-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/*====================================================================*/