summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2016-07-14 14:24:19 -0500
committerGreg Kroah-Hartman <gregkh@google.com>2016-07-15 09:14:27 +0900
commitfc0c38b3d1d6648bfef8ed2478cd2505f6a97475 (patch)
tree81b740108487df3e91aa18b585e60260f949b262 /drivers
parent99ade1766dbd11652905ec91219a643992cb3c18 (diff)
greybus: use memdup_user()
Coccinelle reports that there are two opportunities to use memdup_user() in "authentication.c". This patch simplifies the code in cap_ioctl() by taking advantage of that. Make use of a local variable "size" to improve readability. Signed-off-by: Alex Elder <elder@linaro.org> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/greybus/authentication.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index e4697805530a..a4ac3bbdcb86 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -209,6 +209,7 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd,
struct cap_ioc_get_endpoint_uid endpoint_uid;
struct cap_ioc_get_ims_certificate *ims_cert;
struct cap_ioc_authenticate *authenticate;
+ size_t size;
int ret;
switch (cmd) {
@@ -222,38 +223,26 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd,
return 0;
case CAP_IOC_GET_IMS_CERTIFICATE:
- ims_cert = kzalloc(sizeof(*ims_cert), GFP_KERNEL);
- if (!ims_cert)
- return -ENOMEM;
-
- if (copy_from_user(ims_cert, buf, sizeof(*ims_cert))) {
- ret = -EFAULT;
- goto free_ims_cert;
- }
+ size = sizeof(*ims_cert);
+ ims_cert = memdup_user(buf, size);
+ if (IS_ERR(ims_cert))
+ return PTR_ERR(ims_cert);
ret = cap_get_ims_certificate(cap, ims_cert->certificate_class,
ims_cert->certificate_id,
ims_cert->certificate,
&ims_cert->cert_size,
&ims_cert->result_code);
- if (ret)
- goto free_ims_cert;
-
- if (copy_to_user(buf, ims_cert, sizeof(*ims_cert)))
+ if (!ret && copy_to_user(buf, ims_cert, size))
ret = -EFAULT;
-
-free_ims_cert:
kfree(ims_cert);
+
return ret;
case CAP_IOC_AUTHENTICATE:
- authenticate = kzalloc(sizeof(*authenticate), GFP_KERNEL);
- if (!authenticate)
- return -ENOMEM;
-
- if (copy_from_user(authenticate, buf, sizeof(*authenticate))) {
- ret = -EFAULT;
- goto free_authenticate;
- }
+ size = sizeof(*authenticate);
+ authenticate = memdup_user(buf, size);
+ if (IS_ERR(authenticate))
+ return PTR_ERR(authenticate);
ret = cap_authenticate(cap, authenticate->auth_type,
authenticate->uid,
@@ -262,13 +251,10 @@ free_ims_cert:
authenticate->response,
&authenticate->signature_size,
authenticate->signature);
- if (ret)
- goto free_authenticate;
-
- if (copy_to_user(buf, authenticate, sizeof(*authenticate)))
+ if (!ret && copy_to_user(buf, authenticate, size))
ret = -EFAULT;
-free_authenticate:
kfree(authenticate);
+
return ret;
default:
return -ENOTTY;