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

mei: mei_write: revamp function flow

Use goto statement for error handling instead of deeper if constructs
and rename label 'unlock_dev' to more appropriate 'err'
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3321e738
...@@ -543,24 +543,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -543,24 +543,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (dev->dev_state != MEI_DEV_ENABLED) { if (dev->dev_state != MEI_DEV_ENABLED) {
rets = -ENODEV; rets = -ENODEV;
goto unlock_dev; goto err;
} }
i = mei_me_cl_by_id(dev, cl->me_client_id); i = mei_me_cl_by_id(dev, cl->me_client_id);
if (i < 0) { if (i < 0) {
rets = -ENODEV; rets = -ENODEV;
goto unlock_dev; goto err;
} }
if (length > dev->me_clients[i].props.max_msg_length || length <= 0) { if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
rets = -EMSGSIZE; rets = -EMSGSIZE;
goto unlock_dev; goto err;
} }
if (cl->state != MEI_FILE_CONNECTED) { if (cl->state != MEI_FILE_CONNECTED) {
rets = -ENODEV; rets = -ENODEV;
dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d", dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
cl->host_client_id, cl->me_client_id); cl->host_client_id, cl->me_client_id);
goto unlock_dev; goto err;
} }
if (cl == &dev->iamthif_cl) { if (cl == &dev->iamthif_cl) {
write_cb = find_amthi_read_list_entry(dev, file); write_cb = find_amthi_read_list_entry(dev, file);
...@@ -599,17 +599,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -599,17 +599,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (!write_cb) { if (!write_cb) {
dev_err(&dev->pdev->dev, "write cb allocation failed\n"); dev_err(&dev->pdev->dev, "write cb allocation failed\n");
rets = -ENOMEM; rets = -ENOMEM;
goto unlock_dev; goto err;
} }
rets = mei_io_cb_alloc_req_buf(write_cb, length); rets = mei_io_cb_alloc_req_buf(write_cb, length);
if (rets) if (rets)
goto unlock_dev; goto err;
dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length); dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
if (rets) if (rets)
goto unlock_dev; goto err;
cl->sm_state = 0; cl->sm_state = 0;
if (length == 4 && if (length == 4 &&
...@@ -624,7 +624,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -624,7 +624,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (cl == &dev->iamthif_cl) { if (cl == &dev->iamthif_cl) {
rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu); rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu);
if (rets) if (rets)
goto unlock_dev; goto err;
write_cb->major_file_operations = MEI_IOCTL; write_cb->major_file_operations = MEI_IOCTL;
...@@ -641,7 +641,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -641,7 +641,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (rets) { if (rets) {
dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n", dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n",
rets); rets);
goto unlock_dev; goto err;
} }
} }
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
...@@ -654,51 +654,51 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -654,51 +654,51 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
cl->host_client_id, cl->me_client_id); cl->host_client_id, cl->me_client_id);
rets = mei_flow_ctrl_creds(dev, cl); rets = mei_flow_ctrl_creds(dev, cl);
if (rets < 0) if (rets < 0)
goto unlock_dev; goto err;
if (rets && dev->mei_host_buffer_is_empty) { if (rets == 0 || dev->mei_host_buffer_is_empty == false) {
rets = 0; write_cb->buf_idx = 0;
dev->mei_host_buffer_is_empty = false; mei_hdr.msg_complete = 0;
if (length > mei_hbuf_max_data(dev)) {
mei_hdr.length = mei_hbuf_max_data(dev);
mei_hdr.msg_complete = 0;
} else {
mei_hdr.length = length;
mei_hdr.msg_complete = 1;
}
mei_hdr.host_addr = cl->host_client_id;
mei_hdr.me_addr = cl->me_client_id;
mei_hdr.reserved = 0;
dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n",
*((u32 *) &mei_hdr));
if (mei_write_message(dev, &mei_hdr,
(unsigned char *) (write_cb->request_buffer.data),
mei_hdr.length)) {
rets = -ENODEV;
goto unlock_dev;
}
cl->writing_state = MEI_WRITING; cl->writing_state = MEI_WRITING;
write_cb->buf_idx = mei_hdr.length; goto out;
if (mei_hdr.msg_complete) { }
if (mei_flow_ctrl_reduce(dev, cl)) {
rets = -ENODEV;
goto unlock_dev;
}
list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
} else {
list_add_tail(&write_cb->list, &dev->write_list.list);
}
dev->mei_host_buffer_is_empty = false;
if (length > mei_hbuf_max_data(dev)) {
mei_hdr.length = mei_hbuf_max_data(dev);
mei_hdr.msg_complete = 0;
} else { } else {
mei_hdr.length = length;
mei_hdr.msg_complete = 1;
}
mei_hdr.host_addr = cl->host_client_id;
mei_hdr.me_addr = cl->me_client_id;
mei_hdr.reserved = 0;
dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n",
*((u32 *) &mei_hdr));
if (mei_write_message(dev, &mei_hdr,
write_cb->request_buffer.data, mei_hdr.length)) {
rets = -ENODEV;
goto err;
}
cl->writing_state = MEI_WRITING;
write_cb->buf_idx = mei_hdr.length;
write_cb->buf_idx = 0; out:
cl->writing_state = MEI_WRITING; if (mei_hdr.msg_complete) {
if (mei_flow_ctrl_reduce(dev, cl)) {
rets = -ENODEV;
goto err;
}
list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
} else {
list_add_tail(&write_cb->list, &dev->write_list.list); list_add_tail(&write_cb->list, &dev->write_list.list);
} }
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
return length; return length;
unlock_dev: err:
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
mei_io_cb_free(write_cb); mei_io_cb_free(write_cb);
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