aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-05-22 04:22:49 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-05-22 06:49:37 -0400
commitdf1f1d1cb43b4ffdef5ba5f0623e2f73e94ce030 (patch)
treefdef68b0b5230b9f49f7b26eee33aee4e4f042e3
parent39c5837d7968ffd68e1d3c79efba1631b7f513d9 (diff)
drivers/mtd: Use memdup_user
Use memdup_user when user data is immediately copied into the allocated region. The semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression from,to,size,flag; position p; identifier l1,l2; @@ - to = \(kmalloc@p\|kzalloc@p\)(size,flag); + to = memdup_user(from,size); if ( - to==NULL + IS_ERR(to) || ...) { <+... when != goto l1; - -ENOMEM + PTR_ERR(to) ...+> } - if (copy_from_user(to, from, size) != 0) { - <+... when != goto l2; - -EFAULT - ...+> - } // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/mtdchar.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 8bb5e4a66328..8b223c0343ee 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -404,14 +404,9 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
404 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) 404 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
405 return -EINVAL; 405 return -EINVAL;
406 406
407 ops.oobbuf = kmalloc(length, GFP_KERNEL); 407 ops.oobbuf = memdup_user(ptr, length);
408 if (!ops.oobbuf) 408 if (IS_ERR(ops.oobbuf))
409 return -ENOMEM; 409 return PTR_ERR(ops.oobbuf);
410
411 if (copy_from_user(ops.oobbuf, ptr, length)) {
412 kfree(ops.oobbuf);
413 return -EFAULT;
414 }
415 410
416 start &= ~((uint64_t)mtd->oobsize - 1); 411 start &= ~((uint64_t)mtd->oobsize - 1);
417 ret = mtd->write_oob(mtd, start, &ops); 412 ret = mtd->write_oob(mtd, start, &ops);