Commit 154eb18f authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

mei: use connect_data on the stack

There is no need for dynamic allocation for connect_data.
We can use variable on the stack and make code less
error prone and simple
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4f046e7b
...@@ -433,9 +433,6 @@ static int mei_ioctl_connect_client(struct file *file, ...@@ -433,9 +433,6 @@ static int mei_ioctl_connect_client(struct file *file,
int rets; int rets;
cl = file->private_data; cl = file->private_data;
if (WARN_ON(!cl || !cl->dev))
return -ENODEV;
dev = cl->dev; dev = cl->dev;
if (dev->dev_state != MEI_DEV_ENABLED) { if (dev->dev_state != MEI_DEV_ENABLED) {
...@@ -506,7 +503,6 @@ static int mei_ioctl_connect_client(struct file *file, ...@@ -506,7 +503,6 @@ static int mei_ioctl_connect_client(struct file *file,
return rets; return rets;
} }
/** /**
* mei_ioctl - the IOCTL function * mei_ioctl - the IOCTL function
* *
...@@ -520,7 +516,7 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) ...@@ -520,7 +516,7 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
{ {
struct mei_device *dev; struct mei_device *dev;
struct mei_cl *cl = file->private_data; struct mei_cl *cl = file->private_data;
struct mei_connect_client_data *connect_data = NULL; struct mei_connect_client_data connect_data;
int rets; int rets;
...@@ -540,26 +536,19 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) ...@@ -540,26 +536,19 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
switch (cmd) { switch (cmd) {
case IOCTL_MEI_CONNECT_CLIENT: case IOCTL_MEI_CONNECT_CLIENT:
dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n"); dev_dbg(&dev->pdev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
connect_data = kzalloc(sizeof(struct mei_connect_client_data), if (copy_from_user(&connect_data, (char __user *)data,
GFP_KERNEL);
if (!connect_data) {
rets = -ENOMEM;
goto out;
}
if (copy_from_user(connect_data, (char __user *)data,
sizeof(struct mei_connect_client_data))) { sizeof(struct mei_connect_client_data))) {
dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n"); dev_dbg(&dev->pdev->dev, "failed to copy data from userland\n");
rets = -EFAULT; rets = -EFAULT;
goto out; goto out;
} }
rets = mei_ioctl_connect_client(file, connect_data); rets = mei_ioctl_connect_client(file, &connect_data);
if (rets) if (rets)
goto out; goto out;
/* if all is ok, copying the data back to user. */ /* if all is ok, copying the data back to user. */
if (copy_to_user((char __user *)data, connect_data, if (copy_to_user((char __user *)data, &connect_data,
sizeof(struct mei_connect_client_data))) { sizeof(struct mei_connect_client_data))) {
dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n"); dev_dbg(&dev->pdev->dev, "failed to copy data to userland\n");
rets = -EFAULT; rets = -EFAULT;
...@@ -567,13 +556,13 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) ...@@ -567,13 +556,13 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
} }
break; break;
default: default:
dev_err(&dev->pdev->dev, ": unsupported ioctl %d.\n", cmd); dev_err(&dev->pdev->dev, ": unsupported ioctl %d.\n", cmd);
rets = -ENOIOCTLCMD; rets = -ENOIOCTLCMD;
} }
out: out:
kfree(connect_data);
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
return rets; return rets;
} }
......
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