diff options
author | Julia Lawall <julia@diku.dk> | 2010-07-20 22:08:59 -0400 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-08-07 12:52:31 -0400 |
commit | ad96a7a7ea950d5bc9755f2f568be185c7070f1e (patch) | |
tree | ec2d2c8e2d48c241e05d2acf6506a7105d3ed17c /drivers | |
parent | 6a32a8aed509e71137043d464db4a7fcd88c903e (diff) |
drivers/block: use memdup_user
Use memdup_user when user data is immediately copied into the
allocated region. Some checkpatch cleanups in nearby code.
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>
Cc: Chirag Kantharia <chirag.kantharia@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/cpqarray.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c index 28937b661564..9473215956f9 100644 --- a/drivers/block/cpqarray.c +++ b/drivers/block/cpqarray.c | |||
@@ -1255,17 +1255,11 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io) | |||
1255 | /* Pre submit processing */ | 1255 | /* Pre submit processing */ |
1256 | switch(io->cmd) { | 1256 | switch(io->cmd) { |
1257 | case PASSTHRU_A: | 1257 | case PASSTHRU_A: |
1258 | p = kmalloc(io->sg[0].size, GFP_KERNEL); | 1258 | p = memdup_user(io->sg[0].addr, io->sg[0].size); |
1259 | if (!p) | 1259 | if (IS_ERR(p)) { |
1260 | { | 1260 | error = PTR_ERR(p); |
1261 | error = -ENOMEM; | 1261 | cmd_free(h, c, 0); |
1262 | cmd_free(h, c, 0); | 1262 | return error; |
1263 | return(error); | ||
1264 | } | ||
1265 | if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) { | ||
1266 | kfree(p); | ||
1267 | cmd_free(h, c, 0); | ||
1268 | return -EFAULT; | ||
1269 | } | 1263 | } |
1270 | c->req.hdr.blk = pci_map_single(h->pci_dev, &(io->c), | 1264 | c->req.hdr.blk = pci_map_single(h->pci_dev, &(io->c), |
1271 | sizeof(ida_ioctl_t), | 1265 | sizeof(ida_ioctl_t), |
@@ -1296,18 +1290,12 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io) | |||
1296 | case DIAG_PASS_THRU: | 1290 | case DIAG_PASS_THRU: |
1297 | case COLLECT_BUFFER: | 1291 | case COLLECT_BUFFER: |
1298 | case WRITE_FLASH_ROM: | 1292 | case WRITE_FLASH_ROM: |
1299 | p = kmalloc(io->sg[0].size, GFP_KERNEL); | 1293 | p = memdup_user(io->sg[0].addr, io->sg[0].size); |
1300 | if (!p) | 1294 | if (IS_ERR(p)) { |
1301 | { | 1295 | error = PTR_ERR(p); |
1302 | error = -ENOMEM; | 1296 | cmd_free(h, c, 0); |
1303 | cmd_free(h, c, 0); | 1297 | return error; |
1304 | return(error); | ||
1305 | } | 1298 | } |
1306 | if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) { | ||
1307 | kfree(p); | ||
1308 | cmd_free(h, c, 0); | ||
1309 | return -EFAULT; | ||
1310 | } | ||
1311 | c->req.sg[0].size = io->sg[0].size; | 1299 | c->req.sg[0].size = io->sg[0].size; |
1312 | c->req.sg[0].addr = pci_map_single(h->pci_dev, p, | 1300 | c->req.sg[0].addr = pci_map_single(h->pci_dev, p, |
1313 | c->req.sg[0].size, PCI_DMA_BIDIRECTIONAL); | 1301 | c->req.sg[0].size, PCI_DMA_BIDIRECTIONAL); |