Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangt...@gmail.com>
---
 security/keys/keyctl.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index dd0da25..ce1574a 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -326,14 +326,11 @@ long keyctl_update_key(key_serial_t id,
        /* pull the payload in if one was supplied */
        payload = NULL;
        if (_payload) {
-               ret = -ENOMEM;
-               payload = kmalloc(plen, GFP_KERNEL);
-               if (!payload)
+               payload = memdup_user(_payload, plen);
+               if (IS_ERR(payload)) {
+                       ret = PTR_ERR(payload);
                        goto error;
-
-               ret = -EFAULT;
-               if (copy_from_user(payload, _payload, plen) != 0)
-                       goto error2;
+               }
        }
 
        /* find the target key (which must be writable) */
-- 
2.9.3

Reply via email to