mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [char-misc-next 1/6] mei: mei_write: revamp function flow
@ 2012-11-01 19:17 Tomas Winkler
  2012-11-01 19:17 ` [char-misc-next 2/6] mei: normalize timeouts definitions Tomas Winkler
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tomas Winkler @ 2012-11-01 19:17 UTC (permalink / raw)
  To: gregkh; +Cc: arnd, alan, linux-kernel, Tomas Winkler

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>
---
 drivers/misc/mei/main.c |   88 +++++++++++++++++++++++-----------------------
 1 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index ed4943f..7a03d77 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -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);
@@ -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 &&
@@ -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;
 
@@ -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);
@@ -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;
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-11-01 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-01 19:17 [char-misc-next 1/6] mei: mei_write: revamp function flow Tomas Winkler
2012-11-01 19:17 ` [char-misc-next 2/6] mei: normalize timeouts definitions Tomas Winkler
2012-11-01 19:17 ` [char-misc-next 3/6] mei: extract AMTHI functions into the amthif.c file Tomas Winkler
2012-11-01 19:17 ` [char-misc-next 4/6] mei: mei_clear_list: kill file_temp Tomas Winkler
2012-11-01 19:17 ` [char-misc-next 5/6] mei: use internal watchdog device registration tracking Tomas Winkler
2012-11-01 19:17 ` [char-misc-next 6/6] mei: move amthif specific code from mei_write to mei_amthif_write Tomas Winkler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®