Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 100275
b: refs/heads/master
c: 6071239
h: refs/heads/master
i:
  100273: 58d519f
  100271: 42ae260
v: v3
  • Loading branch information
Jonathan Corbet committed Jun 20, 2008
1 parent 5c5e02f commit 3f58ea0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ea2959a2972410f15155a015df74ce77ac79f8b8
refs/heads/master: 6071239ef1947914892601e36785c7b1cf8b7dd4
22 changes: 16 additions & 6 deletions trunk/drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/smp_lock.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/compatmac.h>
Expand Down Expand Up @@ -86,6 +87,7 @@ static int mtd_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
int devnum = minor >> 1;
int ret = 0;
struct mtd_info *mtd;
struct mtd_file_info *mfi;

Expand All @@ -98,31 +100,39 @@ static int mtd_open(struct inode *inode, struct file *file)
if ((file->f_mode & 2) && (minor & 1))
return -EACCES;

lock_kernel();
mtd = get_mtd_device(NULL, devnum);

if (IS_ERR(mtd))
return PTR_ERR(mtd);
if (IS_ERR(mtd)) {
ret = PTR_ERR(mtd);
goto out;
}

if (MTD_ABSENT == mtd->type) {
put_mtd_device(mtd);
return -ENODEV;
ret = -ENODEV;
goto out;
}

/* You can't open it RW if it's not a writeable device */
if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
put_mtd_device(mtd);
return -EACCES;
ret = -EACCES;
goto out;
}

mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
if (!mfi) {
put_mtd_device(mtd);
return -ENOMEM;
ret = -ENOMEM;
goto out;
}
mfi->mtd = mtd;
file->private_data = mfi;

return 0;
out:
unlock_kernel();
return ret;
} /* mtd_open */

/*====================================================================*/
Expand Down

0 comments on commit 3f58ea0

Please sign in to comment.