aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2008-07-25 10:40:14 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-07-25 10:40:14 -0400
commitff877ea80efa2015b6263766f78ee42c2a1b32f9 (patch)
tree85205005c611ab774702148558321c6fb92f1ccd /drivers/mtd/mtdchar.c
parent30821fee4f0cb3e6d241d9f7ddc37742212e3eb7 (diff)
parentd37e6bf68fc1eb34a4ad21d9ae8890ed37ea80e7 (diff)
Merge branch 'linux-next' of git://git.infradead.org/~dedekind/ubi-2.6
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r--drivers/mtd/mtdchar.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f5061fe72e4c..d2f331876e4c 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/smp_lock.h>
15 16
16#include <linux/mtd/mtd.h> 17#include <linux/mtd/mtd.h>
17#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
@@ -25,10 +26,13 @@ static void mtd_notify_add(struct mtd_info* mtd)
25 if (!mtd) 26 if (!mtd)
26 return; 27 return;
27 28
28 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index); 29 device_create_drvdata(mtd_class, NULL,
30 MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
31 NULL, "mtd%d", mtd->index);
29 32
30 device_create(mtd_class, NULL, 33 device_create_drvdata(mtd_class, NULL,
31 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), "mtd%dro", mtd->index); 34 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
35 NULL, "mtd%dro", mtd->index);
32} 36}
33 37
34static void mtd_notify_remove(struct mtd_info* mtd) 38static void mtd_notify_remove(struct mtd_info* mtd)
@@ -84,6 +88,7 @@ static int mtd_open(struct inode *inode, struct file *file)
84{ 88{
85 int minor = iminor(inode); 89 int minor = iminor(inode);
86 int devnum = minor >> 1; 90 int devnum = minor >> 1;
91 int ret = 0;
87 struct mtd_info *mtd; 92 struct mtd_info *mtd;
88 struct mtd_file_info *mfi; 93 struct mtd_file_info *mfi;
89 94
@@ -96,31 +101,39 @@ static int mtd_open(struct inode *inode, struct file *file)
96 if ((file->f_mode & 2) && (minor & 1)) 101 if ((file->f_mode & 2) && (minor & 1))
97 return -EACCES; 102 return -EACCES;
98 103
104 lock_kernel();
99 mtd = get_mtd_device(NULL, devnum); 105 mtd = get_mtd_device(NULL, devnum);
100 106
101 if (IS_ERR(mtd)) 107 if (IS_ERR(mtd)) {
102 return PTR_ERR(mtd); 108 ret = PTR_ERR(mtd);
109 goto out;
110 }
103 111
104 if (MTD_ABSENT == mtd->type) { 112 if (MTD_ABSENT == mtd->type) {
105 put_mtd_device(mtd); 113 put_mtd_device(mtd);
106 return -ENODEV; 114 ret = -ENODEV;
115 goto out;
107 } 116 }
108 117
109 /* You can't open it RW if it's not a writeable device */ 118 /* You can't open it RW if it's not a writeable device */
110 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { 119 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
111 put_mtd_device(mtd); 120 put_mtd_device(mtd);
112 return -EACCES; 121 ret = -EACCES;
122 goto out;
113 } 123 }
114 124
115 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); 125 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
116 if (!mfi) { 126 if (!mfi) {
117 put_mtd_device(mtd); 127 put_mtd_device(mtd);
118 return -ENOMEM; 128 ret = -ENOMEM;
129 goto out;
119 } 130 }
120 mfi->mtd = mtd; 131 mfi->mtd = mtd;
121 file->private_data = mfi; 132 file->private_data = mfi;
122 133
123 return 0; 134out:
135 unlock_kernel();
136 return ret;
124} /* mtd_open */ 137} /* mtd_open */
125 138
126/*====================================================================*/ 139/*====================================================================*/