Commit fc0c38b3 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

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: default avatarAlex Elder <elder@linaro.org>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 99ade176
...@@ -209,6 +209,7 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd, ...@@ -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_endpoint_uid endpoint_uid;
struct cap_ioc_get_ims_certificate *ims_cert; struct cap_ioc_get_ims_certificate *ims_cert;
struct cap_ioc_authenticate *authenticate; struct cap_ioc_authenticate *authenticate;
size_t size;
int ret; int ret;
switch (cmd) { switch (cmd) {
...@@ -222,38 +223,26 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd, ...@@ -222,38 +223,26 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd,
return 0; return 0;
case CAP_IOC_GET_IMS_CERTIFICATE: case CAP_IOC_GET_IMS_CERTIFICATE:
ims_cert = kzalloc(sizeof(*ims_cert), GFP_KERNEL); size = sizeof(*ims_cert);
if (!ims_cert) ims_cert = memdup_user(buf, size);
return -ENOMEM; if (IS_ERR(ims_cert))
return PTR_ERR(ims_cert);
if (copy_from_user(ims_cert, buf, sizeof(*ims_cert))) {
ret = -EFAULT;
goto free_ims_cert;
}
ret = cap_get_ims_certificate(cap, ims_cert->certificate_class, ret = cap_get_ims_certificate(cap, ims_cert->certificate_class,
ims_cert->certificate_id, ims_cert->certificate_id,
ims_cert->certificate, ims_cert->certificate,
&ims_cert->cert_size, &ims_cert->cert_size,
&ims_cert->result_code); &ims_cert->result_code);
if (ret) if (!ret && copy_to_user(buf, ims_cert, size))
goto free_ims_cert;
if (copy_to_user(buf, ims_cert, sizeof(*ims_cert)))
ret = -EFAULT; ret = -EFAULT;
free_ims_cert:
kfree(ims_cert); kfree(ims_cert);
return ret; return ret;
case CAP_IOC_AUTHENTICATE: case CAP_IOC_AUTHENTICATE:
authenticate = kzalloc(sizeof(*authenticate), GFP_KERNEL); size = sizeof(*authenticate);
if (!authenticate) authenticate = memdup_user(buf, size);
return -ENOMEM; if (IS_ERR(authenticate))
return PTR_ERR(authenticate);
if (copy_from_user(authenticate, buf, sizeof(*authenticate))) {
ret = -EFAULT;
goto free_authenticate;
}
ret = cap_authenticate(cap, authenticate->auth_type, ret = cap_authenticate(cap, authenticate->auth_type,
authenticate->uid, authenticate->uid,
...@@ -262,13 +251,10 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd, ...@@ -262,13 +251,10 @@ static int cap_ioctl(struct gb_cap *cap, unsigned int cmd,
authenticate->response, authenticate->response,
&authenticate->signature_size, &authenticate->signature_size,
authenticate->signature); authenticate->signature);
if (ret) if (!ret && copy_to_user(buf, authenticate, size))
goto free_authenticate;
if (copy_to_user(buf, authenticate, sizeof(*authenticate)))
ret = -EFAULT; ret = -EFAULT;
free_authenticate:
kfree(authenticate); kfree(authenticate);
return ret; return ret;
default: default:
return -ENOTTY; return -ENOTTY;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment