Skip to content

Commit

Permalink
mei: mei_write: revamp function flow
Browse files Browse the repository at this point in the history
Use goto statement for error handling instead of deeper if constructs
and rename label 'unlock_dev' to more appropriate 'err'

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Tomas Winkler authored and Greg Kroah-Hartman committed Nov 1, 2012
1 parent 3321e73 commit b0d0cf7
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions drivers/misc/mei/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,24 +543,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,

if (dev->dev_state != MEI_DEV_ENABLED) {
rets = -ENODEV;
goto unlock_dev;
goto err;
}

i = mei_me_cl_by_id(dev, cl->me_client_id);
if (i < 0) {
rets = -ENODEV;
goto unlock_dev;
goto err;
}
if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
rets = -EMSGSIZE;
goto unlock_dev;
goto err;
}

if (cl->state != MEI_FILE_CONNECTED) {
rets = -ENODEV;
dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
cl->host_client_id, cl->me_client_id);
goto unlock_dev;
goto err;
}
if (cl == &dev->iamthif_cl) {
write_cb = find_amthi_read_list_entry(dev, file);
Expand Down Expand Up @@ -599,17 +599,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (!write_cb) {
dev_err(&dev->pdev->dev, "write cb allocation failed\n");
rets = -ENOMEM;
goto unlock_dev;
goto err;
}
rets = mei_io_cb_alloc_req_buf(write_cb, length);
if (rets)
goto unlock_dev;
goto err;

dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);

rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
if (rets)
goto unlock_dev;
goto err;

cl->sm_state = 0;
if (length == 4 &&
Expand All @@ -624,7 +624,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (cl == &dev->iamthif_cl) {
rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu);
if (rets)
goto unlock_dev;
goto err;

write_cb->major_file_operations = MEI_IOCTL;

Expand All @@ -641,7 +641,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (rets) {
dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n",
rets);
goto unlock_dev;
goto err;
}
}
mutex_unlock(&dev->device_lock);
Expand All @@ -654,51 +654,51 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
cl->host_client_id, cl->me_client_id);
rets = mei_flow_ctrl_creds(dev, cl);
if (rets < 0)
goto unlock_dev;
goto err;

if (rets && dev->mei_host_buffer_is_empty) {
rets = 0;
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 {
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;
}
if (rets == 0 || dev->mei_host_buffer_is_empty == false) {
write_cb->buf_idx = 0;
mei_hdr.msg_complete = 0;
cl->writing_state = MEI_WRITING;
write_cb->buf_idx = mei_hdr.length;
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);
}
goto out;
}

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 {
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;
cl->writing_state = MEI_WRITING;
out:
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);
}

mutex_unlock(&dev->device_lock);
return length;

unlock_dev:
err:
mutex_unlock(&dev->device_lock);
mei_io_cb_free(write_cb);
return rets;
Expand Down

0 comments on commit b0d0cf7

Please sign in to comment.