Skip to content

Commit

Permalink
powerpc/powernv: use memdup_user
Browse files Browse the repository at this point in the history
Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
geliangtang authored and mpe committed Jul 24, 2017
1 parent 31f8eb7 commit 5588b29
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions arch/powerpc/platforms/powernv/opal-prd.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,16 @@ static ssize_t opal_prd_write(struct file *file, const char __user *buf,

size = be16_to_cpu(hdr.size);

msg = kmalloc(size, GFP_KERNEL);
if (!msg)
return -ENOMEM;

rc = copy_from_user(msg, buf, size);
if (rc) {
size = -EFAULT;
goto out_free;
}
msg = memdup_user(buf, size);
if (IS_ERR(msg))
return PTR_ERR(msg);

rc = opal_prd_msg(msg);
if (rc) {
pr_warn("write: opal_prd_msg returned %d\n", rc);
size = -EIO;
}

out_free:
kfree(msg);

return size;
Expand Down

0 comments on commit 5588b29

Please sign in to comment.