Skip to content

Commit

Permalink
bfa: replace 2 kzalloc/copy_from_user by memdup_user
Browse files Browse the repository at this point in the history
This patch also removes unnecessary printk(KERN_INFO

Signed-off-by: Fabian Frederick <[email protected]>
Acked-by: Anil Gurumurthy <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
Fabian Frederick authored and Christoph Hellwig committed Nov 20, 2014
1 parent 1b33ef2 commit 9f30b67
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions drivers/scsi/bfa/bfad_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,9 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
unsigned long flags;
void *kern_buf;

kern_buf = kzalloc(nbytes, GFP_KERNEL);

if (!kern_buf) {
printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
bfad->inst_no);
return -ENOMEM;
}

if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
kfree(kern_buf);
return -ENOMEM;
}
kern_buf = memdup_user(buf, nbytes);
if (IS_ERR(kern_buf))
return PTR_ERR(kern_buf);

rc = sscanf(kern_buf, "%x:%x", &addr, &len);
if (rc < 2) {
Expand Down Expand Up @@ -336,18 +327,9 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
unsigned long flags;
void *kern_buf;

kern_buf = kzalloc(nbytes, GFP_KERNEL);

if (!kern_buf) {
printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
bfad->inst_no);
return -ENOMEM;
}

if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
kfree(kern_buf);
return -ENOMEM;
}
kern_buf = memdup_user(buf, nbytes);
if (IS_ERR(kern_buf))
return PTR_ERR(kern_buf);

rc = sscanf(kern_buf, "%x:%x", &addr, &val);
if (rc < 2) {
Expand Down

0 comments on commit 9f30b67

Please sign in to comment.