diff options
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r-- | drivers/mtd/mtdchar.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 5b6acfcb2b88..3013d0883b97 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include <linux/device.h> | 8 | #include <linux/device.h> |
9 | #include <linux/fs.h> | 9 | #include <linux/fs.h> |
10 | #include <linux/err.h> | ||
10 | #include <linux/init.h> | 11 | #include <linux/init.h> |
11 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -100,8 +101,8 @@ static int mtd_open(struct inode *inode, struct file *file) | |||
100 | 101 | ||
101 | mtd = get_mtd_device(NULL, devnum); | 102 | mtd = get_mtd_device(NULL, devnum); |
102 | 103 | ||
103 | if (!mtd) | 104 | if (IS_ERR(mtd)) |
104 | return -ENODEV; | 105 | return PTR_ERR(mtd); |
105 | 106 | ||
106 | if (MTD_ABSENT == mtd->type) { | 107 | if (MTD_ABSENT == mtd->type) { |
107 | put_mtd_device(mtd); | 108 | put_mtd_device(mtd); |
@@ -431,7 +432,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
431 | if(!(file->f_mode & 2)) | 432 | if(!(file->f_mode & 2)) |
432 | return -EPERM; | 433 | return -EPERM; |
433 | 434 | ||
434 | erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL); | 435 | erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL); |
435 | if (!erase) | 436 | if (!erase) |
436 | ret = -ENOMEM; | 437 | ret = -ENOMEM; |
437 | else { | 438 | else { |
@@ -440,7 +441,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
440 | 441 | ||
441 | init_waitqueue_head(&waitq); | 442 | init_waitqueue_head(&waitq); |
442 | 443 | ||
443 | memset (erase,0,sizeof(struct erase_info)); | ||
444 | if (copy_from_user(&erase->addr, argp, | 444 | if (copy_from_user(&erase->addr, argp, |
445 | sizeof(struct erase_info_user))) { | 445 | sizeof(struct erase_info_user))) { |
446 | kfree(erase); | 446 | kfree(erase); |
@@ -499,13 +499,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
499 | if (ret) | 499 | if (ret) |
500 | return ret; | 500 | return ret; |
501 | 501 | ||
502 | ops.len = buf.length; | ||
503 | ops.ooblen = buf.length; | 502 | ops.ooblen = buf.length; |
504 | ops.ooboffs = buf.start & (mtd->oobsize - 1); | 503 | ops.ooboffs = buf.start & (mtd->oobsize - 1); |
505 | ops.datbuf = NULL; | 504 | ops.datbuf = NULL; |
506 | ops.mode = MTD_OOB_PLACE; | 505 | ops.mode = MTD_OOB_PLACE; |
507 | 506 | ||
508 | if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs)) | 507 | if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) |
509 | return -EINVAL; | 508 | return -EINVAL; |
510 | 509 | ||
511 | ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); | 510 | ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); |
@@ -520,7 +519,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
520 | buf.start &= ~(mtd->oobsize - 1); | 519 | buf.start &= ~(mtd->oobsize - 1); |
521 | ret = mtd->write_oob(mtd, buf.start, &ops); | 520 | ret = mtd->write_oob(mtd, buf.start, &ops); |
522 | 521 | ||
523 | if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen, | 522 | if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen, |
524 | sizeof(uint32_t))) | 523 | sizeof(uint32_t))) |
525 | ret = -EFAULT; | 524 | ret = -EFAULT; |
526 | 525 | ||
@@ -548,7 +547,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
548 | if (ret) | 547 | if (ret) |
549 | return ret; | 548 | return ret; |
550 | 549 | ||
551 | ops.len = buf.length; | ||
552 | ops.ooblen = buf.length; | 550 | ops.ooblen = buf.length; |
553 | ops.ooboffs = buf.start & (mtd->oobsize - 1); | 551 | ops.ooboffs = buf.start & (mtd->oobsize - 1); |
554 | ops.datbuf = NULL; | 552 | ops.datbuf = NULL; |
@@ -564,10 +562,10 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
564 | buf.start &= ~(mtd->oobsize - 1); | 562 | buf.start &= ~(mtd->oobsize - 1); |
565 | ret = mtd->read_oob(mtd, buf.start, &ops); | 563 | ret = mtd->read_oob(mtd, buf.start, &ops); |
566 | 564 | ||
567 | if (put_user(ops.retlen, (uint32_t __user *)argp)) | 565 | if (put_user(ops.oobretlen, (uint32_t __user *)argp)) |
568 | ret = -EFAULT; | 566 | ret = -EFAULT; |
569 | else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf, | 567 | else if (ops.oobretlen && copy_to_user(buf.ptr, ops.oobbuf, |
570 | ops.retlen)) | 568 | ops.oobretlen)) |
571 | ret = -EFAULT; | 569 | ret = -EFAULT; |
572 | 570 | ||
573 | kfree(ops.oobbuf); | 571 | kfree(ops.oobbuf); |
@@ -616,6 +614,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
616 | memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos)); | 614 | memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos)); |
617 | memcpy(&oi.oobfree, mtd->ecclayout->oobfree, | 615 | memcpy(&oi.oobfree, mtd->ecclayout->oobfree, |
618 | sizeof(oi.oobfree)); | 616 | sizeof(oi.oobfree)); |
617 | oi.eccbytes = mtd->ecclayout->eccbytes; | ||
619 | 618 | ||
620 | if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo))) | 619 | if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo))) |
621 | return -EFAULT; | 620 | return -EFAULT; |
@@ -715,7 +714,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
715 | if (!mtd->ecclayout) | 714 | if (!mtd->ecclayout) |
716 | return -EOPNOTSUPP; | 715 | return -EOPNOTSUPP; |
717 | 716 | ||
718 | if (copy_to_user(argp, &mtd->ecclayout, | 717 | if (copy_to_user(argp, mtd->ecclayout, |
719 | sizeof(struct nand_ecclayout))) | 718 | sizeof(struct nand_ecclayout))) |
720 | return -EFAULT; | 719 | return -EFAULT; |
721 | break; | 720 | break; |