Simplify the user copy code by using strndup_user().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
if (!ibm || !ibm->write)
return -EINVAL;
- if (count > PAGE_SIZE - 1)
- return -EINVAL;
-
- kernbuf = kmalloc(count + 1, GFP_KERNEL);
- if (!kernbuf)
- return -ENOMEM;
- if (copy_from_user(kernbuf, userbuf, count)) {
- kfree(kernbuf);
- return -EFAULT;
- }
+ kernbuf = strndup_user(userbuf, PAGE_SIZE);
+ if (IS_ERR(kernbuf))
+ return PTR_ERR(kernbuf);
- kernbuf[count] = 0;
ret = ibm->write(kernbuf);
if (ret == 0)
ret = count;