All of lore.kernel.org
 help / color / mirror / Atom feed
* (no subject)
@ 2012-02-24  1:38 Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 1/9] mei: cosmetic cleanup in interrupt.c Devin J. Pohly
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel

This is just a number of cleanups in mei driver, mostly interrupt.c, to make
the code a bit more idiomatic and kernel-like.  The only patch which should
change the operation of the code is PATCH 4/9, where an obviously wrong "return
~Exxx" was fixed.

Broken apart by type of cleanup.  For reducing indentation, separated by how
complex the job was, from easiest to hardest.

 drivers/staging/mei/init.c        |    2 +-
 drivers/staging/mei/interrupt.c   |  799 +++++++++++++++++--------------------
 drivers/staging/mei/mei_dev.h     |    3 +-
 drivers/staging/mei/mei_version.h |    6 +-
 drivers/staging/mei/wd.c          |   23 +-
 5 files changed, 387 insertions(+), 446 deletions(-)


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

* [PATCH 1/9] mei: cosmetic cleanup in interrupt.c
  2012-02-24  1:38 Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  2:51   ` Greg KH
  2012-02-24  1:38 ` [PATCH 2/9] mei: factor some bits of code outside if blocks Devin J. Pohly
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Tabs, spaces, long lines, lines that could be combined, superfluous
parentheses, etc.  Also uses DIV_ROUND_UP and sizeof(*ptr) where
appropriate.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/init.c        |    2 +-
 drivers/staging/mei/interrupt.c   |  239 +++++++++++++++++--------------------
 drivers/staging/mei/mei_dev.h     |    3 +-
 drivers/staging/mei/mei_version.h |    6 +-
 drivers/staging/mei/wd.c          |   23 ++--
 5 files changed, 131 insertions(+), 142 deletions(-)

diff --git a/drivers/staging/mei/init.c b/drivers/staging/mei/init.c
index 4ac3696..1a00ede 100644
--- a/drivers/staging/mei/init.c
+++ b/drivers/staging/mei/init.c
@@ -455,7 +455,7 @@ void mei_allocate_me_clients_storage(struct mei_device *dev)
  * @dev: the device structure
  *
  * returns:
- * 	< 0 - Error.
+ *  < 0 - Error.
  *  = 0 - no more clients.
  *  = 1 - still have clients to send properties request.
  */
diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index 3544fee..4914589 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -14,7 +14,6 @@
  *
  */
 
-
 #include <linux/pci.h>
 #include <linux/kthread.h>
 #include <linux/interrupt.h>
@@ -26,7 +25,6 @@
 #include "hw.h"
 #include "interface.h"
 
-
 /**
  * mei_interrupt_quick_handler - The ISR of the MEI device
  *
@@ -69,7 +67,6 @@ static void _mei_cmpl(struct mei_cl *cl, struct mei_cl_cb *cb_pos)
 		cl->reading_state = MEI_READ_COMPLETE;
 		if (waitqueue_active(&cl->rx_wait))
 			wake_up_interruptible(&cl->rx_wait);
-
 	}
 }
 
@@ -101,7 +98,6 @@ static void _mei_cmpl_iamthif(struct mei_device *dev, struct mei_cl_cb *cb_pos)
 	wake_up_interruptible(&dev->iamthif_cl.wait);
 }
 
-
 /**
  * mei_irq_thread_read_amthi_message - bottom half read routine after ISR to
  * handle the read amthi message data processing.
@@ -150,14 +146,13 @@ static int mei_irq_thread_read_amthi_message(struct mei_io_list *complete_list,
 		return -ENODEV;
 
 	dev->iamthif_stall_timer = 0;
-	cb->information =	dev->iamthif_msg_buf_index;
+	cb->information = dev->iamthif_msg_buf_index;
 	cb->read_time = jiffies;
 	if (dev->iamthif_ioctl && cl == &dev->iamthif_cl) {
 		/* found the iamthif cb */
 		dev_dbg(&dev->pdev->dev, "complete the amthi read cb.\n ");
 		dev_dbg(&dev->pdev->dev, "add the amthi read cb to complete.\n ");
-		list_add_tail(&cb->cb_list,
-						&complete_list->mei_cb.cb_list);
+		list_add_tail(&cb->cb_list, &complete_list->mei_cb.cb_list);
 	}
 	return 0;
 }
@@ -266,11 +261,10 @@ quit:
  */
 static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots)
 {
-
 	if (((*slots) * sizeof(u32)) >= (sizeof(struct mei_msg_hdr)
 			+ sizeof(struct hbm_flow_control))) {
-		*slots -= (sizeof(struct mei_msg_hdr) +
-				sizeof(struct hbm_flow_control) + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+				sizeof(struct hbm_flow_control), sizeof(u32));
 		if (!mei_send_flow_control(dev, &dev->iamthif_cl)) {
 			dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
 		} else {
@@ -307,8 +301,9 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
 {
 	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_client_disconnect_request))) {
-		*slots -= (sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_client_disconnect_request) + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+			sizeof(struct hbm_client_disconnect_request),
+			sizeof(u32));
 
 		if (!mei_disconnect(dev, cl)) {
 			cl->status = 0;
@@ -345,7 +340,7 @@ static bool is_treat_specially_client(struct mei_cl *cl,
 {
 
 	if (cl->host_client_id == rs->host_addr &&
-	    cl->me_client_id == rs->me_addr) {
+			cl->me_client_id == rs->me_addr) {
 		if (!rs->status) {
 			cl->state = MEI_FILE_CONNECTED;
 			cl->status = 0;
@@ -449,7 +444,7 @@ static void mei_client_disconnect_response(struct mei_device *dev,
 
 		dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n");
 		if (cl->host_client_id == rs->host_addr &&
-		    cl->me_client_id == rs->me_addr) {
+					cl->me_client_id == rs->me_addr) {
 
 			list_del(&cb_pos->cb_list);
 			if (!rs->status)
@@ -483,7 +478,7 @@ static int same_flow_addr(struct mei_cl *cl, struct hbm_flow_control *flow)
  * @flow: flow control.
  */
 static void add_single_flow_creds(struct mei_device *dev,
-				  struct hbm_flow_control *flow)
+				struct hbm_flow_control *flow)
 {
 	struct mei_me_client *client;
 	int i;
@@ -494,9 +489,9 @@ static void add_single_flow_creds(struct mei_device *dev,
 			if (client->props.single_recv_buf) {
 				client->mei_flow_ctrl_creds++;
 				dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
-				    flow->me_addr);
+						flow->me_addr);
 				dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
-				    client->mei_flow_ctrl_creds);
+						client->mei_flow_ctrl_creds);
 			} else {
 				BUG();	/* error in flow control */
 			}
@@ -526,18 +521,18 @@ static void mei_client_flow_control_response(struct mei_device *dev,
 			dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in file_list\n");
 
 			dev_dbg(&dev->pdev->dev, "cl of host client %d ME client %d.\n",
-			    cl_pos->host_client_id,
-			    cl_pos->me_client_id);
+						cl_pos->host_client_id,
+						cl_pos->me_client_id);
 			dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n",
-			    flow_control->host_addr,
-			    flow_control->me_addr);
+						flow_control->host_addr,
+						flow_control->me_addr);
 			if (same_flow_addr(cl_pos, flow_control)) {
 				dev_dbg(&dev->pdev->dev, "recv ctrl msg for host  %d ME %d.\n",
-				    flow_control->host_addr,
-				    flow_control->me_addr);
+							flow_control->host_addr,
+							flow_control->me_addr);
 				cl_pos->mei_flow_ctrl_creds++;
 				dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n",
-				    cl_pos->mei_flow_ctrl_creds);
+						cl_pos->mei_flow_ctrl_creds);
 				break;
 			}
 		}
@@ -553,7 +548,7 @@ static void mei_client_flow_control_response(struct mei_device *dev,
  * returns !=0, same; 0,not.
  */
 static int same_disconn_addr(struct mei_cl *cl,
-			     struct hbm_client_disconnect_request *disconn)
+			struct hbm_client_disconnect_request *disconn)
 {
 	return (cl->host_client_id == disconn->host_addr &&
 		cl->me_client_id == disconn->me_addr);
@@ -591,8 +586,7 @@ static void mei_client_disconnect_request(struct mei_device *dev,
 				(struct mei_msg_hdr *) &dev->ext_msg_buf[0];
 			mei_hdr->host_addr = 0;
 			mei_hdr->me_addr = 0;
-			mei_hdr->length =
-				sizeof(struct hbm_client_connect_response);
+			mei_hdr->length = sizeof(*disconnect_res);
 			mei_hdr->msg_complete = 1;
 			mei_hdr->reserved = 0;
 
@@ -610,7 +604,6 @@ static void mei_client_disconnect_request(struct mei_device *dev,
 	}
 }
 
-
 /**
  * mei_irq_thread_read_bus_message - bottom half read routine after ISR to
  * handle the read bus message cmd processing.
@@ -647,7 +640,8 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 			dev->version.major_version = HBM_MAJOR_VERSION;
 			dev->version.minor_version = HBM_MINOR_VERSION;
 			if (dev->mei_state == MEI_INIT_CLIENTS &&
-			    dev->init_clients_state == MEI_START_MESSAGE) {
+					dev->init_clients_state ==
+					MEI_START_MESSAGE) {
 				dev->init_clients_timer = 0;
 				mei_host_enum_clients_message(dev);
 			} else {
@@ -661,21 +655,19 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 			/* send stop message */
 			mei_hdr->host_addr = 0;
 			mei_hdr->me_addr = 0;
-			mei_hdr->length = sizeof(struct hbm_host_stop_request);
+			mei_hdr->length = sizeof(*host_stop_req);
 			mei_hdr->msg_complete = 1;
 			mei_hdr->reserved = 0;
 
 			host_stop_req = (struct hbm_host_stop_request *)
 							&dev->wr_msg_buf[1];
 
-			memset(host_stop_req,
-					0,
-					sizeof(struct hbm_host_stop_request));
+			memset(host_stop_req, 0, sizeof(*host_stop_req));
 			host_stop_req->cmd.cmd = HOST_STOP_REQ_CMD;
 			host_stop_req->reason = DRIVER_STOP_REQUEST;
 			mei_write_message(dev, mei_hdr,
-					   (unsigned char *) (host_stop_req),
-					   mei_hdr->length);
+					(unsigned char *) (host_stop_req),
+					mei_hdr->length);
 			dev_dbg(&dev->pdev->dev, "version mismatch.\n");
 			return;
 		}
@@ -685,16 +677,14 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 		break;
 
 	case CLIENT_CONNECT_RES_CMD:
-		connect_res =
-			(struct hbm_client_connect_response *) mei_msg;
+		connect_res = (struct hbm_client_connect_response *) mei_msg;
 		mei_client_connect_response(dev, connect_res);
 		dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
 		wake_up(&dev->wait_recvd_msg);
 		break;
 
 	case CLIENT_DISCONNECT_RES_CMD:
-		disconnect_res =
-			(struct hbm_client_connect_response *) mei_msg;
+		disconnect_res = (struct hbm_client_connect_response *) mei_msg;
 		mei_client_disconnect_response(dev, disconnect_res);
 		dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
 		wake_up(&dev->wait_recvd_msg);
@@ -720,12 +710,12 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 						= props_res->client_properties;
 
 			if (dev->mei_state == MEI_INIT_CLIENTS &&
-			    dev->init_clients_state ==
+					dev->init_clients_state ==
 					MEI_CLIENT_PROPERTIES_MESSAGE) {
 				dev->me_client_index++;
 				dev->me_client_presentation_num++;
 
-				/** Send Client Propeties request **/
+				/* Send Client Properties request */
 				res = mei_host_client_properties(dev);
 				if (res < 0) {
 					dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
@@ -733,24 +723,28 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 				} else if (!res) {
 					/*
 					 * No more clients to send to.
-					 * Clear Map for indicating now ME clients
-					 * with associated host client
+					 * Clear Map for indicating now ME
+					 * clients with associated host client
 					 */
-					bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX);
+					bitmap_zero(dev->host_clients_map,
+							MEI_CLIENTS_MAX);
 					dev->open_handle_count = 0;
 
 					/*
 					 * Reserving the first three client IDs
-					 * Client Id 0 - Reserved for MEI Bus Message communications
+					 * Client Id 0 - Reserved for MEI Bus
+					 *               Message communications
 					 * Client Id 1 - Reserved for Watchdog
 					 * Client ID 2 - Reserved for AMTHI
 					 */
 					bitmap_set(dev->host_clients_map, 0, 3);
 					dev->mei_state = MEI_ENABLED;
 
-					/* if wd initialization fails, initialization the AMTHI client,
-					 * otherwise the AMTHI client will be initialized after the WD client connect response
-					 * will be received
+					/* if wd initialization fails,
+					 * initialize the AMTHI client,
+					 * otherwise the AMTHI client will be
+					 * initialized after the WD client
+					 * connect response is received
 					 */
 					if (mei_wd_host_init(dev))
 						mei_host_init_iamthif(dev);
@@ -772,14 +766,15 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 		enum_res = (struct hbm_host_enum_response *) mei_msg;
 		memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
 		if (dev->mei_state == MEI_INIT_CLIENTS &&
-		    dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) {
-				dev->init_clients_timer = 0;
-				dev->me_client_presentation_num = 0;
-				dev->me_client_index = 0;
-				mei_allocate_me_clients_storage(dev);
-				dev->init_clients_state =
-					MEI_CLIENT_PROPERTIES_MESSAGE;
-				mei_host_client_properties(dev);
+				dev->init_clients_state ==
+				MEI_ENUM_CLIENTS_MESSAGE) {
+			dev->init_clients_timer = 0;
+			dev->me_client_presentation_num = 0;
+			dev->me_client_index = 0;
+			mei_allocate_me_clients_storage(dev);
+			dev->init_clients_state =
+				MEI_CLIENT_PROPERTIES_MESSAGE;
+			mei_host_client_properties(dev);
 		} else {
 			dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n");
 			mei_reset(dev, 1);
@@ -805,12 +800,12 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 		mei_hdr = (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
 		mei_hdr->host_addr = 0;
 		mei_hdr->me_addr = 0;
-		mei_hdr->length = sizeof(struct hbm_host_stop_request);
+		mei_hdr->length = sizeof(*host_stop_req);
 		mei_hdr->msg_complete = 1;
 		mei_hdr->reserved = 0;
 		host_stop_req =
 			(struct hbm_host_stop_request *) &dev->ext_msg_buf[1];
-		memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request));
+		memset(host_stop_req, 0, sizeof(*host_stop_req));
 		host_stop_req->cmd.cmd = HOST_STOP_REQ_CMD;
 		host_stop_req->reason = DRIVER_STOP_REQUEST;
 		host_stop_req->reserved[0] = 0;
@@ -821,11 +816,9 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 	default:
 		BUG();
 		break;
-
 	}
 }
 
-
 /**
  * _mei_hb_read - processes read related operation.
  *
@@ -837,15 +830,15 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
  *
  * returns 0, OK; otherwise, error.
  */
-static int _mei_irq_thread_read(struct mei_device *dev,	s32 *slots,
+static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
 			struct mei_cl_cb *cb_pos,
 			struct mei_cl *cl,
 			struct mei_io_list *cmpl_list)
 {
 	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_flow_control))) {
-		*slots -= (sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_flow_control) + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+			sizeof(struct hbm_flow_control), sizeof(u32));
 		if (!mei_send_flow_control(dev, cl)) {
 			cl->status = -ENODEV;
 			cb_pos->information = 0;
@@ -865,7 +858,6 @@ static int _mei_irq_thread_read(struct mei_device *dev,	s32 *slots,
 	return 0;
 }
 
-
 /**
  * _mei_irq_thread_ioctl - processes ioctl related operation.
  *
@@ -885,8 +877,8 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
 	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_client_connect_request))) {
 		cl->state = MEI_FILE_CONNECTING;
-		*slots -= (sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_client_connect_request) + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+			sizeof(struct hbm_client_connect_request), sizeof(u32));
 		if (!mei_connect(dev, cl)) {
 			cl->status = -ENODEV;
 			cb_pos->information = 0;
@@ -917,7 +909,7 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
  *
  * returns 0, OK; otherwise, error.
  */
-static int _mei_irq_thread_cmpl(struct mei_device *dev,	s32 *slots,
+static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
 			struct mei_cl_cb *cb_pos,
 			struct mei_cl *cl,
 			struct mei_io_list *cmpl_list)
@@ -942,8 +934,8 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev,	s32 *slots,
 				cb_pos->information);
 		dev_dbg(&dev->pdev->dev, "mei_hdr->length  =%d\n",
 				mei_hdr->length);
-		*slots -= (sizeof(struct mei_msg_hdr) +
-				mei_hdr->length + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+				mei_hdr->length, sizeof(u32));
 		if (!mei_write_message(dev, mei_hdr,
 				(unsigned char *)
 				(cb_pos->request_buffer.data +
@@ -966,13 +958,12 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev,	s32 *slots,
 		mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
 		mei_hdr->host_addr = cl->host_client_id;
 		mei_hdr->me_addr = cl->me_client_id;
-		mei_hdr->length =
-			(*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
+		mei_hdr->length = (*slots * sizeof(u32)) - sizeof(*mei_hdr);
 		mei_hdr->msg_complete = 0;
 		mei_hdr->reserved = 0;
 
-		(*slots) -= (sizeof(struct mei_msg_hdr) +
-				mei_hdr->length + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+				mei_hdr->length, sizeof(u32));
 		if (!mei_write_message(dev, mei_hdr,
 					(unsigned char *)
 					(cb_pos->request_buffer.data +
@@ -1031,8 +1022,8 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
 		mei_hdr->msg_complete = 1;
 		mei_hdr->reserved = 0;
 
-		*slots -= (sizeof(struct mei_msg_hdr) +
-				mei_hdr->length + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+				mei_hdr->length, sizeof(u32));
 
 		if (!mei_write_message(dev, mei_hdr,
 					(dev->iamthif_msg_buf +
@@ -1061,13 +1052,12 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
 		mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
 		mei_hdr->host_addr = cl->host_client_id;
 		mei_hdr->me_addr = cl->me_client_id;
-		mei_hdr->length =
-			(*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
+		mei_hdr->length = (*slots * sizeof(u32)) - sizeof(*mei_hdr);
 		mei_hdr->msg_complete = 0;
 		mei_hdr->reserved = 0;
 
-		*slots -= (sizeof(struct mei_msg_hdr) +
-				mei_hdr->length + 3) / 4;
+		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+				mei_hdr->length, sizeof(u32));
 
 		if (!mei_write_message(dev, mei_hdr,
 					(dev->iamthif_msg_buf +
@@ -1129,7 +1119,8 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 					cl_pos->host_client_id,
 					cl_pos->me_client_id);
 			if (cl_pos->host_client_id == mei_hdr->host_addr &&
-			    cl_pos->me_client_id == mei_hdr->me_addr)
+					cl_pos->me_client_id ==
+					mei_hdr->me_addr)
 				break;
 		}
 
@@ -1154,8 +1145,8 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 		mei_irq_thread_read_bus_message(dev, mei_hdr);
 		dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n");
 	} else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
-		   (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
-		   (dev->iamthif_state == MEI_IAMTHIF_READING)) {
+				(MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
+				(dev->iamthif_state == MEI_IAMTHIF_READING)) {
 		dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
 		dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
 				mei_hdr->length);
@@ -1167,7 +1158,7 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 	} else {
 		dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n");
 		ret = mei_irq_thread_read_client_message(cmpl_list,
-							 dev, mei_hdr);
+							dev, mei_hdr);
 		if (ret)
 			goto end;
 
@@ -1188,7 +1179,6 @@ end:
 	return ret;
 }
 
-
 /**
  * mei_irq_thread_write_handler - bottom half write routine after
  * ISR to handle the write processing.
@@ -1220,15 +1210,15 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 	list = &dev->write_waiting_list;
 	list_for_each_entry_safe(pos, next,
 			&list->mei_cb.cb_list, cb_list) {
-		cl = (struct mei_cl *)pos->file_private;
+		cl = (struct mei_cl *) pos->file_private;
 		if (cl == NULL)
 			continue;
 
 		cl->status = 0;
 		list_del(&pos->cb_list);
 		if (MEI_WRITING == cl->writing_state &&
-		   (pos->major_file_operations == MEI_WRITE) &&
-		   (cl != &dev->iamthif_cl)) {
+				(pos->major_file_operations == MEI_WRITE) &&
+				(cl != &dev->iamthif_cl)) {
 			dev_dbg(&dev->pdev->dev,
 				"MEI WRITE COMPLETE\n");
 			cl->writing_state = MEI_WRITE_COMPLETE;
@@ -1274,12 +1264,14 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 			dev->wd_pending = false;
 
 			if (dev->wd_timeout) {
-				*slots -= (sizeof(struct mei_msg_hdr) +
-					 MEI_START_WD_DATA_SIZE + 3) / 4;
+				*slots -= DIV_ROUND_UP(
+					sizeof(struct mei_msg_hdr) +
+					MEI_START_WD_DATA_SIZE, sizeof(u32));
 				dev->wd_due_counter = 2;
 			} else {
-				*slots -= (sizeof(struct mei_msg_hdr) +
-					 MEI_WD_PARAMS_SIZE + 3) / 4;
+				*slots -= DIV_ROUND_UP(
+					sizeof(struct mei_msg_hdr) +
+					MEI_WD_PARAMS_SIZE, sizeof(u32));
 				dev->wd_due_counter = 0;
 			}
 
@@ -1300,34 +1292,32 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 		switch (pos->major_file_operations) {
 		case MEI_CLOSE:
 			/* send disconnect message */
-			ret = _mei_irq_thread_close(dev, slots, pos, cl, cmpl_list);
+			ret = _mei_irq_thread_close(dev, slots, pos, cl,
+					cmpl_list);
 			if (ret)
 				return ret;
-
 			break;
 		case MEI_READ:
 			/* send flow control message */
-			ret = _mei_irq_thread_read(dev, slots, pos, cl, cmpl_list);
+			ret = _mei_irq_thread_read(dev, slots, pos, cl,
+					cmpl_list);
 			if (ret)
 				return ret;
-
 			break;
 		case MEI_IOCTL:
 			/* connect message */
 			if (mei_other_client_is_connecting(dev, cl))
 				continue;
-			ret = _mei_irq_thread_ioctl(dev, slots, pos, cl, cmpl_list);
+			ret = _mei_irq_thread_ioctl(dev, slots, pos, cl,
+					cmpl_list);
 			if (ret)
 				return ret;
-
 			break;
-
 		default:
 			BUG();
 		}
-
 	}
-	/* complete  write list CB */
+	/* complete write list CB */
 	dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
 	list_for_each_entry_safe(pos, next,
 			&dev->write_list.mei_cb.cb_list, cb_list) {
@@ -1339,14 +1329,13 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 			if (!mei_flow_ctrl_creds(dev, cl)) {
 				dev_dbg(&dev->pdev->dev,
 					"No flow control"
-				    " credentials for client"
-				    " %d, not sending.\n",
-				    cl->host_client_id);
+					" credentials for client"
+					" %d, not sending.\n",
+					cl->host_client_id);
 				continue;
 			}
-			ret = _mei_irq_thread_cmpl(dev, slots,
-					    pos,
-					    cl, cmpl_list);
+			ret = _mei_irq_thread_cmpl(dev, slots, pos, cl,
+					cmpl_list);
 			if (ret)
 				return ret;
 
@@ -1356,15 +1345,12 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 			if (!mei_flow_ctrl_creds(dev, cl)) {
 				dev_dbg(&dev->pdev->dev,
 					"No flow control"
-				    " credentials for amthi"
-				    " client %d.\n",
-				    cl->host_client_id);
+					" credentials for amthi"
+					" client %d.\n",
+					cl->host_client_id);
 				continue;
 			}
-			ret = _mei_irq_thread_cmpl_iamthif(dev,
-						slots,
-						pos,
-						cl,
+			ret = _mei_irq_thread_cmpl_iamthif(dev, slots, pos, cl,
 						cmpl_list);
 			if (ret)
 				return ret;
@@ -1375,8 +1361,6 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 	return 0;
 }
 
-
-
 /**
  * mei_timer - timer function.
  *
@@ -1390,13 +1374,12 @@ void mei_timer(struct work_struct *work)
 	struct mei_cl *cl_pos = NULL;
 	struct mei_cl *cl_next = NULL;
 	struct list_head *amthi_complete_list = NULL;
-	struct mei_cl_cb  *cb_pos = NULL;
-	struct mei_cl_cb  *cb_next = NULL;
+	struct mei_cl_cb *cb_pos = NULL;
+	struct mei_cl_cb *cb_next = NULL;
 
 	struct mei_device *dev = container_of(work,
 					struct mei_device, timer_work.work);
 
-
 	mutex_lock(&dev->device_lock);
 	if (dev->mei_state != MEI_ENABLED) {
 		if (dev->mei_state == MEI_INIT_CLIENTS) {
@@ -1410,7 +1393,7 @@ void mei_timer(struct work_struct *work)
 		}
 		goto out;
 	}
-	/*** connect/disconnect timeouts ***/
+	/* connect/disconnect timeouts */
 	list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
 		if (cl_pos->timer_count) {
 			if (--cl_pos->timer_count == 0) {
@@ -1442,7 +1425,6 @@ void mei_timer(struct work_struct *work)
 	}
 
 	if (dev->iamthif_timer) {
-
 		timeout = dev->iamthif_timer +
 				msecs_to_jiffies(IAMTHIF_READ_TIMER);
 
@@ -1461,7 +1443,8 @@ void mei_timer(struct work_struct *work)
 			amthi_complete_list = &dev->amthi_read_complete_list.
 					mei_cb.cb_list;
 
-			list_for_each_entry_safe(cb_pos, cb_next, amthi_complete_list, cb_list) {
+			list_for_each_entry_safe(cb_pos, cb_next,
+					amthi_complete_list, cb_list) {
 
 				cl_pos = cb_pos->file_object->private_data;
 
@@ -1486,8 +1469,8 @@ out:
 }
 
 /**
- *  mei_interrupt_thread_handler - function called after ISR to handle the interrupt
- * processing.
+ * mei_interrupt_thread_handler - function called after ISR to handle the
+ * interrupt processing.
  *
  * @irq: The irq number
  * @dev_id: pointer to the device structure
@@ -1503,8 +1486,7 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
 	struct mei_cl *cl;
 	s32 slots;
 	int rets;
-	bool  bus_message_received;
-
+	bool bus_message_received;
 
 	dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
 	/* initialize our complete list */
@@ -1521,15 +1503,15 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
 
 	/* check if ME wants a reset */
 	if ((dev->me_hw_state & ME_RDY_HRA) == 0 &&
-	    dev->mei_state != MEI_RESETING &&
-	    dev->mei_state != MEI_INITIALIZING) {
+			dev->mei_state != MEI_RESETING &&
+			dev->mei_state != MEI_INITIALIZING) {
 		dev_dbg(&dev->pdev->dev, "FW not ready.\n");
 		mei_reset(dev, 1);
 		mutex_unlock(&dev->device_lock);
 		return IRQ_HANDLED;
 	}
 
-	/*  check if we need to start the dev */
+	/* check if we need to start the dev */
 	if ((dev->host_hw_state & H_RDY) == 0) {
 		if ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA) {
 			dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
@@ -1581,7 +1563,6 @@ end:
 	if (list_empty(&complete_list.mei_cb.cb_list))
 		return IRQ_HANDLED;
 
-
 	list_for_each_entry_safe(cb_pos, cb_next,
 			&complete_list.mei_cb.cb_list, cb_list) {
 		cl = (struct mei_cl *)cb_pos->file_private;
diff --git a/drivers/staging/mei/mei_dev.h b/drivers/staging/mei/mei_dev.h
index 82bacfc..8ed54da 100644
--- a/drivers/staging/mei/mei_dev.h
+++ b/drivers/staging/mei/mei_dev.h
@@ -271,7 +271,8 @@ int mei_hw_init(struct mei_device *dev);
 int mei_task_initialize_clients(void *data);
 int mei_initialize_clients(struct mei_device *dev);
 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
-void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
+void mei_remove_client_from_file_list(struct mei_device *dev,
+		u8 host_client_id);
 void mei_host_init_iamthif(struct mei_device *dev);
 void mei_allocate_me_clients_storage(struct mei_device *dev);
 
diff --git a/drivers/staging/mei/mei_version.h b/drivers/staging/mei/mei_version.h
index 075bad8..70de574 100644
--- a/drivers/staging/mei/mei_version.h
+++ b/drivers/staging/mei/mei_version.h
@@ -23,9 +23,9 @@
 #define QUICK_FIX_NUMBER	20
 #define VER_BUILD		1
 
-#define MEI_DRV_VER1 __stringify(MAJOR_VERSION) "." __stringify(MINOR_VERSION)
-#define MEI_DRV_VER2 __stringify(QUICK_FIX_NUMBER) "." __stringify(VER_BUILD)
+#define MEI_DRV_VER1 (__stringify(MAJOR_VERSION) "." __stringify(MINOR_VERSION))
+#define MEI_DRV_VER2 (__stringify(QUICK_FIX_NUMBER) "." __stringify(VER_BUILD))
 
-#define MEI_DRIVER_VERSION	MEI_DRV_VER1 "." MEI_DRV_VER2
+#define MEI_DRIVER_VERSION	(MEI_DRV_VER1 "." MEI_DRV_VER2)
 
 #endif
diff --git a/drivers/staging/mei/wd.c b/drivers/staging/mei/wd.c
index 8094941..e1b6b2e 100644
--- a/drivers/staging/mei/wd.c
+++ b/drivers/staging/mei/wd.c
@@ -75,7 +75,8 @@ bool mei_wd_host_init(struct mei_device *dev)
 	dev_dbg(&dev->pdev->dev, "check wd_cl\n");
 	if (MEI_FILE_CONNECTING == dev->wd_cl.state) {
 		if (!mei_connect(dev, &dev->wd_cl)) {
-			dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n");
+			dev_dbg(&dev->pdev->dev,
+					"Failed to connect to WD client\n");
 			dev->wd_cl.state = MEI_FILE_DISCONNECTED;
 			dev->wd_cl.host_client_id = 0;
 			ret = false;
@@ -210,13 +211,15 @@ static int mei_wd_ops_start(struct watchdog_device *wd_dev)
 	mutex_lock(&dev->device_lock);
 
 	if (dev->mei_state != MEI_ENABLED) {
-		dev_dbg(&dev->pdev->dev, "mei_state != MEI_ENABLED  mei_state= %d\n",
-		    dev->mei_state);
+		dev_dbg(&dev->pdev->dev,
+			"mei_state != MEI_ENABLED  mei_state= %d\n",
+			dev->mei_state);
 		goto end_unlock;
 	}
 
 	if (dev->wd_cl.state != MEI_FILE_CONNECTED)	{
-		dev_dbg(&dev->pdev->dev, "MEI Driver is not connected to Watchdog Client\n");
+		dev_dbg(&dev->pdev->dev,
+			"MEI Driver is not connected to Watchdog Client\n");
 		goto end_unlock;
 	}
 
@@ -288,7 +291,8 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
 		}
 
 		if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) {
-			dev_dbg(&dev->pdev->dev, "mei_flow_ctrl_reduce() failed.\n");
+			dev_dbg(&dev->pdev->dev,
+					"mei_flow_ctrl_reduce() failed.\n");
 			ret = -EIO;
 			goto end;
 		}
@@ -310,7 +314,8 @@ end:
  *
  * returns 0 if success, negative errno code for failure
  */
-static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout)
+static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev,
+		unsigned int timeout)
 {
 	struct mei_device *dev;
 	dev = pci_get_drvdata(mei_device);
@@ -363,10 +368,12 @@ void  mei_watchdog_register(struct mei_device *dev)
 	dev->wd_due_counter = !!dev->wd_timeout;
 
 	if (watchdog_register_device(&amt_wd_dev)) {
-		dev_err(&dev->pdev->dev, "unable to register watchdog device.\n");
+		dev_err(&dev->pdev->dev,
+				"unable to register watchdog device.\n");
 		dev->wd_interface_reg = false;
 	} else {
-		dev_dbg(&dev->pdev->dev, "successfully register watchdog interface.\n");
+		dev_dbg(&dev->pdev->dev,
+				"successfully register watchdog interface.\n");
 		dev->wd_interface_reg = true;
 	}
 }
-- 
1.7.9.2


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

* [PATCH 2/9] mei: factor some bits of code outside if blocks
  2012-02-24  1:38 Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 1/9] mei: cosmetic cleanup in interrupt.c Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 3/9] mei: more idiomatic variable/label usage Devin J. Pohly
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index 4914589..d1291ae 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -1336,9 +1336,6 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 			}
 			ret = _mei_irq_thread_cmpl(dev, slots, pos, cl,
 					cmpl_list);
-			if (ret)
-				return ret;
-
 		} else if (cl == &dev->iamthif_cl) {
 			/* IAMTHIF IOCTL */
 			dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n");
@@ -1352,11 +1349,9 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 			}
 			ret = _mei_irq_thread_cmpl_iamthif(dev, slots, pos, cl,
 						cmpl_list);
-			if (ret)
-				return ret;
-
 		}
-
+		if (ret)
+			return ret;
 	}
 	return 0;
 }
@@ -1523,13 +1518,11 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
 			 * start sending messages.
 			 */
 			mei_host_start_message(dev);
-			mutex_unlock(&dev->device_lock);
-			return IRQ_HANDLED;
 		} else {
 			dev_dbg(&dev->pdev->dev, "FW not ready.\n");
-			mutex_unlock(&dev->device_lock);
-			return IRQ_HANDLED;
 		}
+		mutex_unlock(&dev->device_lock);
+		return IRQ_HANDLED;
 	}
 	/* check slots avalable for reading */
 	slots = mei_count_full_read_slots(dev);
-- 
1.7.9.2


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

* [PATCH 3/9] mei: more idiomatic variable/label usage
  2012-02-24  1:38 Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 1/9] mei: cosmetic cleanup in interrupt.c Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 2/9] mei: factor some bits of code outside if blocks Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 4/9] mei: return values are -Exxx, not ~Exxx! Devin J. Pohly
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Rename rets -> ret, and quit -> out.  Also, use return instead of goto
end when end is just a return anyway.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index d1291ae..0601789 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -194,7 +194,7 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,
 
 	dev_dbg(&dev->pdev->dev, "start client msg\n");
 	if (list_empty(&dev->read_list.mei_cb.cb_list))
-		goto quit;
+		goto out;
 
 	list_for_each_entry_safe(cb_pos, cb_next,
 			&dev->read_list.mei_cb.cb_list, cb_list) {
@@ -239,7 +239,7 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,
 
 	}
 
-quit:
+out:
 	dev_dbg(&dev->pdev->dev, "message read\n");
 	if (!buffer) {
 		mei_read_slots(dev, (unsigned char *) dev->rd_msg_buf,
@@ -1106,8 +1106,7 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 
 	if (mei_hdr->reserved || !dev->rd_msg_hdr) {
 		dev_dbg(&dev->pdev->dev, "corrupted message header.\n");
-		ret = -EBADMSG;
-		goto end;
+		return -EBADMSG;
 	}
 
 	if (mei_hdr->host_addr || mei_hdr->me_addr) {
@@ -1126,8 +1125,7 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 
 		if (&cl_pos->link == &dev->file_list) {
 			dev_dbg(&dev->pdev->dev, "corrupted message header\n");
-			ret = -EBADMSG;
-			goto end;
+			return -EBADMSG;
 		}
 	}
 	if (((*slots) * sizeof(u32)) < mei_hdr->length) {
@@ -1135,8 +1133,7 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 				"we can't read the message slots =%08x.\n",
 				*slots);
 		/* we can't read the message */
-		ret = -ERANGE;
-		goto end;
+		return -ERANGE;
 	}
 
 	/* decide where to read the message too */
@@ -1153,14 +1150,14 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 		ret = mei_irq_thread_read_amthi_message(cmpl_list,
 							dev, mei_hdr);
 		if (ret)
-			goto end;
+			return ret;
 
 	} else {
 		dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n");
 		ret = mei_irq_thread_read_client_message(cmpl_list,
 							dev, mei_hdr);
 		if (ret)
-			goto end;
+			return ret;
 
 	}
 
@@ -1172,11 +1169,9 @@ static int mei_irq_thread_read_handler(struct mei_io_list *cmpl_list,
 		/* overflow - reset */
 		dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n");
 		/* set the event since message has been read */
-		ret = -ERANGE;
-		goto end;
+		return -ERANGE;
 	}
-end:
-	return ret;
+	return 0;
 }
 
 /**
@@ -1480,7 +1475,7 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
 	struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
 	struct mei_cl *cl;
 	s32 slots;
-	int rets;
+	int ret;
 	bool bus_message_received;
 
 	dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
@@ -1532,11 +1527,11 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
 		dev_dbg(&dev->pdev->dev, "slots =%08x  extra_write_index =%08x.\n",
 				slots, dev->extra_write_index);
 		dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n");
-		rets = mei_irq_thread_read_handler(&complete_list, dev, &slots);
-		if (rets)
+		ret = mei_irq_thread_read_handler(&complete_list, dev, &slots);
+		if (ret)
 			goto end;
 	}
-	rets = mei_irq_thread_write_handler(&complete_list, dev, &slots);
+	mei_irq_thread_write_handler(&complete_list, dev, &slots);
 end:
 	dev_dbg(&dev->pdev->dev, "end of bottom half function.\n");
 	dev->host_hw_state = mei_hcsr_read(dev);
-- 
1.7.9.2


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

* [PATCH 4/9] mei: return values are -Exxx, not ~Exxx!
  2012-02-24  1:38 Devin J. Pohly
                   ` (2 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 3/9] mei: more idiomatic variable/label usage Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-27 16:35   ` Tomas Winkler
  2012-02-24  1:38 ` [PATCH 5/9] mei: remove indentation where else follows return Devin J. Pohly
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

There's no way this is what was intended! :)

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index 0601789..b024270 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -1273,7 +1273,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 		}
 	}
 	if (dev->stop)
-		return ~ENODEV;
+		return -ENODEV;
 
 	/* complete control write list CB */
 	dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
-- 
1.7.9.2


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

* [PATCH 5/9] mei: remove indentation where else follows return
  2012-02-24  1:38 Devin J. Pohly
                   ` (3 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 4/9] mei: return values are -Exxx, not ~Exxx! Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 6/9] mei: reduce indentation with early returns Devin J. Pohly
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

If a function returns early as the last statement of an if block, the
"else" is pretty much implied.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   58 ++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index b024270..ade5574 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -945,14 +945,13 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
 			list_move_tail(&cb_pos->cb_list,
 				&cmpl_list->mei_cb.cb_list);
 			return -ENODEV;
-		} else {
-			if (mei_flow_ctrl_reduce(dev, cl))
-				return -ENODEV;
-			cl->status = 0;
-			cb_pos->information += mei_hdr->length;
-			list_move_tail(&cb_pos->cb_list,
-				&dev->write_waiting_list.mei_cb.cb_list);
 		}
+		if (mei_flow_ctrl_reduce(dev, cl))
+			return -ENODEV;
+		cl->status = 0;
+		cb_pos->information += mei_hdr->length;
+		list_move_tail(&cb_pos->cb_list,
+			&dev->write_waiting_list.mei_cb.cb_list);
 	} else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) {
 		/* buffer is still empty */
 		mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
@@ -973,18 +972,17 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
 			list_move_tail(&cb_pos->cb_list,
 				&cmpl_list->mei_cb.cb_list);
 			return -ENODEV;
-		} else {
-			cb_pos->information += mei_hdr->length;
-			dev_dbg(&dev->pdev->dev,
-					"cb_pos->request_buffer.size =%d"
-					" mei_hdr->msg_complete = %d\n",
-					cb_pos->request_buffer.size,
-					mei_hdr->msg_complete);
-			dev_dbg(&dev->pdev->dev, "cb_pos->information  =%lu\n",
-					cb_pos->information);
-			dev_dbg(&dev->pdev->dev, "mei_hdr->length  =%d\n",
-					mei_hdr->length);
 		}
+		cb_pos->information += mei_hdr->length;
+		dev_dbg(&dev->pdev->dev,
+				"cb_pos->request_buffer.size =%d"
+				" mei_hdr->msg_complete = %d\n",
+				cb_pos->request_buffer.size,
+				mei_hdr->msg_complete);
+		dev_dbg(&dev->pdev->dev, "cb_pos->information  =%lu\n",
+				cb_pos->information);
+		dev_dbg(&dev->pdev->dev, "mei_hdr->length  =%d\n",
+				mei_hdr->length);
 		return -EMSGSIZE;
 	} else {
 		return -EBADMSG;
@@ -1033,20 +1031,18 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
 			cl->status = -ENODEV;
 			list_del(&cb_pos->cb_list);
 			return -ENODEV;
-		} else {
-			if (mei_flow_ctrl_reduce(dev, cl))
-				return -ENODEV;
-			dev->iamthif_msg_buf_index += mei_hdr->length;
-			cb_pos->information = dev->iamthif_msg_buf_index;
-			cl->status = 0;
-			dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
-			dev->iamthif_flow_control_pending = true;
-			/* save iamthif cb sent to amthi client */
-			dev->iamthif_current_cb = cb_pos;
-			list_move_tail(&cb_pos->cb_list,
-				&dev->write_waiting_list.mei_cb.cb_list);
-
 		}
+		if (mei_flow_ctrl_reduce(dev, cl))
+			return -ENODEV;
+		dev->iamthif_msg_buf_index += mei_hdr->length;
+		cb_pos->information = dev->iamthif_msg_buf_index;
+		cl->status = 0;
+		dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
+		dev->iamthif_flow_control_pending = true;
+		/* save iamthif cb sent to amthi client */
+		dev->iamthif_current_cb = cb_pos;
+		list_move_tail(&cb_pos->cb_list,
+			&dev->write_waiting_list.mei_cb.cb_list);
 	} else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) {
 			/* buffer is still empty */
 		mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
-- 
1.7.9.2


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

* [PATCH 6/9] mei: reduce indentation with early returns
  2012-02-24  1:38 Devin J. Pohly
                   ` (4 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 5/9] mei: remove indentation where else follows return Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 7/9] mei: reduce indentation by combining if blocks Devin J. Pohly
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Rather than check an error condition in the last part of an if-else set,
check it up front, return, and then don't bother with the "else" part.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |  352 +++++++++++++++++++--------------------
 1 file changed, 170 insertions(+), 182 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index ade5574..541d018 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -261,26 +261,26 @@ out:
  */
 static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots)
 {
-	if (((*slots) * sizeof(u32)) >= (sizeof(struct mei_msg_hdr)
-			+ sizeof(struct hbm_flow_control))) {
-		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
-				sizeof(struct hbm_flow_control), sizeof(u32));
-		if (!mei_send_flow_control(dev, &dev->iamthif_cl)) {
-			dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
-		} else {
-			dev_dbg(&dev->pdev->dev, "iamthif flow control success\n");
-			dev->iamthif_state = MEI_IAMTHIF_READING;
-			dev->iamthif_flow_control_pending = false;
-			dev->iamthif_msg_buf_index = 0;
-			dev->iamthif_msg_buf_size = 0;
-			dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER;
-			dev->mei_host_buffer_is_empty =
-					mei_host_buffer_is_empty(dev);
-		}
-		return 0;
-	} else {
+	if (*slots * sizeof(u32) < (sizeof(struct mei_msg_hdr)
+			+ sizeof(struct hbm_flow_control)))
 		return -EMSGSIZE;
+	*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+			sizeof(struct hbm_flow_control),
+			sizeof(u32));
+	if (!mei_send_flow_control(dev, &dev->iamthif_cl)) {
+		dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
+		return 0;
 	}
+
+	dev_dbg(&dev->pdev->dev, "iamthif flow control success\n");
+	dev->iamthif_state = MEI_IAMTHIF_READING;
+	dev->iamthif_flow_control_pending = false;
+	dev->iamthif_msg_buf_index = 0;
+	dev->iamthif_msg_buf_size = 0;
+	dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER;
+	dev->mei_host_buffer_is_empty =
+		mei_host_buffer_is_empty(dev);
+	return 0;
 }
 
 /**
@@ -299,31 +299,27 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
 				struct mei_cl *cl,
 				struct mei_io_list *cmpl_list)
 {
-	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_client_disconnect_request))) {
-		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+	if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
+			sizeof(struct hbm_client_disconnect_request)))
+		return -EBADMSG;
+
+	*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_client_disconnect_request),
 			sizeof(u32));
 
-		if (!mei_disconnect(dev, cl)) {
-			cl->status = 0;
-			cb_pos->information = 0;
-			list_move_tail(&cb_pos->cb_list,
-					&cmpl_list->mei_cb.cb_list);
-			return -EMSGSIZE;
-		} else {
-			cl->state = MEI_FILE_DISCONNECTING;
-			cl->status = 0;
-			cb_pos->information = 0;
-			list_move_tail(&cb_pos->cb_list,
-					&dev->ctrl_rd_list.mei_cb.cb_list);
-			cl->timer_count = MEI_CONNECT_TIMEOUT;
-		}
-	} else {
-		/* return the cancel routine */
-		return -EBADMSG;
+	if (!mei_disconnect(dev, cl)) {
+		cl->status = 0;
+		cb_pos->information = 0;
+		list_move_tail(&cb_pos->cb_list, &cmpl_list->mei_cb.cb_list);
+		return -EMSGSIZE;
 	}
 
+	cl->state = MEI_FILE_DISCONNECTING;
+	cl->status = 0;
+	cb_pos->information = 0;
+	list_move_tail(&cb_pos->cb_list, &dev->ctrl_rd_list.mei_cb.cb_list);
+	cl->timer_count = MEI_CONNECT_TIMEOUT;
+
 	return 0;
 }
 
@@ -338,22 +334,20 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
 static bool is_treat_specially_client(struct mei_cl *cl,
 		struct hbm_client_connect_response *rs)
 {
+	if (cl->host_client_id != rs->host_addr ||
+				cl->me_client_id != rs->me_addr)
+		return false;
 
-	if (cl->host_client_id == rs->host_addr &&
-			cl->me_client_id == rs->me_addr) {
-		if (!rs->status) {
-			cl->state = MEI_FILE_CONNECTED;
-			cl->status = 0;
-
-		} else {
-			cl->state = MEI_FILE_DISCONNECTED;
-			cl->status = -ENODEV;
-		}
-		cl->timer_count = 0;
-
-		return true;
+	if (!rs->status) {
+		cl->state = MEI_FILE_CONNECTED;
+		cl->status = 0;
+	} else {
+		cl->state = MEI_FILE_DISCONNECTED;
+		cl->status = -ENODEV;
 	}
-	return false;
+	cl->timer_count = 0;
+
+	return true;
 }
 
 /**
@@ -486,15 +480,14 @@ static void add_single_flow_creds(struct mei_device *dev,
 	for (i = 0; i < dev->me_clients_num; i++) {
 		client = &dev->me_clients[i];
 		if (client && flow->me_addr == client->client_id) {
-			if (client->props.single_recv_buf) {
-				client->mei_flow_ctrl_creds++;
-				dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
-						flow->me_addr);
-				dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
-						client->mei_flow_ctrl_creds);
-			} else {
-				BUG();	/* error in flow control */
-			}
+			/* bug on error in flow control */
+			BUG_ON(!client->props.single_recv_buf);
+
+			client->mei_flow_ctrl_creds++;
+			dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
+					flow->me_addr);
+			dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
+					client->mei_flow_ctrl_creds);
 		}
 	}
 }
@@ -569,38 +562,37 @@ static void mei_client_disconnect_request(struct mei_device *dev,
 	struct mei_cl *cl_next = NULL;
 
 	list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
-		if (same_disconn_addr(cl_pos, disconnect_req)) {
-			dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
-					disconnect_req->host_addr,
-					disconnect_req->me_addr);
-			cl_pos->state = MEI_FILE_DISCONNECTED;
-			cl_pos->timer_count = 0;
-			if (cl_pos == &dev->wd_cl) {
-				dev->wd_due_counter = 0;
-				dev->wd_pending = false;
-			} else if (cl_pos == &dev->iamthif_cl)
-				dev->iamthif_timer = 0;
-
-			/* prepare disconnect response */
-			mei_hdr =
-				(struct mei_msg_hdr *) &dev->ext_msg_buf[0];
-			mei_hdr->host_addr = 0;
-			mei_hdr->me_addr = 0;
-			mei_hdr->length = sizeof(*disconnect_res);
-			mei_hdr->msg_complete = 1;
-			mei_hdr->reserved = 0;
+		if (!same_disconn_addr(cl_pos, disconnect_req))
+			continue;
 
-			disconnect_res =
-				(struct hbm_client_connect_response *)
-				&dev->ext_msg_buf[1];
-			disconnect_res->host_addr = cl_pos->host_client_id;
-			disconnect_res->me_addr = cl_pos->me_client_id;
-			*(u8 *) (&disconnect_res->cmd) =
-				CLIENT_DISCONNECT_RES_CMD;
-			disconnect_res->status = 0;
-			dev->extra_write_index = 2;
-			break;
+		dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
+				disconnect_req->host_addr,
+				disconnect_req->me_addr);
+		cl_pos->state = MEI_FILE_DISCONNECTED;
+		cl_pos->timer_count = 0;
+		if (cl_pos == &dev->wd_cl) {
+			dev->wd_due_counter = 0;
+			dev->wd_pending = false;
+		} else if (cl_pos == &dev->iamthif_cl) {
+			dev->iamthif_timer = 0;
 		}
+
+		/* prepare disconnect response */
+		mei_hdr = (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
+		mei_hdr->host_addr = 0;
+		mei_hdr->me_addr = 0;
+		mei_hdr->length = sizeof(*disconnect_res);
+		mei_hdr->msg_complete = 1;
+		mei_hdr->reserved = 0;
+
+		disconnect_res = (struct hbm_client_connect_response *)
+			&dev->ext_msg_buf[1];
+		disconnect_res->host_addr = cl_pos->host_client_id;
+		disconnect_res->me_addr = cl_pos->me_client_id;
+		*(u8 *) (&disconnect_res->cmd) = CLIENT_DISCONNECT_RES_CMD;
+		disconnect_res->status = 0;
+		dev->extra_write_index = 2;
+		break;
 	}
 }
 
@@ -704,82 +696,82 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 			return;
 		}
 		if (dev->me_clients[dev->me_client_presentation_num]
-					.client_id == props_res->address) {
-
-			dev->me_clients[dev->me_client_presentation_num].props
-						= props_res->client_properties;
+					.client_id != props_res->address) {
+			dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n");
+			mei_reset(dev, 1);
+			return;
+		}
 
-			if (dev->mei_state == MEI_INIT_CLIENTS &&
-					dev->init_clients_state ==
-					MEI_CLIENT_PROPERTIES_MESSAGE) {
-				dev->me_client_index++;
-				dev->me_client_presentation_num++;
-
-				/* Send Client Properties request */
-				res = mei_host_client_properties(dev);
-				if (res < 0) {
-					dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
-					return;
-				} else if (!res) {
-					/*
-					 * No more clients to send to.
-					 * Clear Map for indicating now ME
-					 * clients with associated host client
-					 */
-					bitmap_zero(dev->host_clients_map,
-							MEI_CLIENTS_MAX);
-					dev->open_handle_count = 0;
-
-					/*
-					 * Reserving the first three client IDs
-					 * Client Id 0 - Reserved for MEI Bus
-					 *               Message communications
-					 * Client Id 1 - Reserved for Watchdog
-					 * Client ID 2 - Reserved for AMTHI
-					 */
-					bitmap_set(dev->host_clients_map, 0, 3);
-					dev->mei_state = MEI_ENABLED;
-
-					/* if wd initialization fails,
-					 * initialize the AMTHI client,
-					 * otherwise the AMTHI client will be
-					 * initialized after the WD client
-					 * connect response is received
-					 */
-					if (mei_wd_host_init(dev))
-						mei_host_init_iamthif(dev);
-				}
+		dev->me_clients[dev->me_client_presentation_num].props
+					= props_res->client_properties;
 
-			} else {
-				dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message");
-				mei_reset(dev, 1);
-				return;
-			}
-		} else {
-			dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n");
+		if (dev->mei_state != MEI_INIT_CLIENTS ||
+				dev->init_clients_state !=
+				MEI_CLIENT_PROPERTIES_MESSAGE) {
+			dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message");
 			mei_reset(dev, 1);
 			return;
 		}
+
+		dev->me_client_index++;
+		dev->me_client_presentation_num++;
+
+		/* Send Client Properties request */
+		res = mei_host_client_properties(dev);
+		if (res < 0) {
+			dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
+			return;
+		}
+		if (res)
+			break;
+
+		/*
+		 * No more clients to send to.
+		 * Clear Map for indicating now ME
+		 * clients with associated host client
+		 */
+		bitmap_zero(dev->host_clients_map,
+				MEI_CLIENTS_MAX);
+		dev->open_handle_count = 0;
+
+		/*
+		 * Reserving the first three client IDs
+		 * Client Id 0 - Reserved for MEI Bus
+		 *               Message communications
+		 * Client Id 1 - Reserved for Watchdog
+		 * Client ID 2 - Reserved for AMTHI
+		 */
+		bitmap_set(dev->host_clients_map, 0, 3);
+		dev->mei_state = MEI_ENABLED;
+
+		/* if wd initialization fails,
+		 * initialize the AMTHI client,
+		 * otherwise the AMTHI client will be
+		 * initialized after the WD client
+		 * connect response is received
+		 */
+		if (mei_wd_host_init(dev))
+			mei_host_init_iamthif(dev);
 		break;
 
 	case HOST_ENUM_RES_CMD:
 		enum_res = (struct hbm_host_enum_response *) mei_msg;
 		memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
-		if (dev->mei_state == MEI_INIT_CLIENTS &&
-				dev->init_clients_state ==
-				MEI_ENUM_CLIENTS_MESSAGE) {
-			dev->init_clients_timer = 0;
-			dev->me_client_presentation_num = 0;
-			dev->me_client_index = 0;
-			mei_allocate_me_clients_storage(dev);
-			dev->init_clients_state =
-				MEI_CLIENT_PROPERTIES_MESSAGE;
-			mei_host_client_properties(dev);
-		} else {
+		if (dev->mei_state != MEI_INIT_CLIENTS ||
+					dev->init_clients_state !=
+					MEI_ENUM_CLIENTS_MESSAGE) {
 			dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n");
 			mei_reset(dev, 1);
 			return;
 		}
+
+		dev->init_clients_timer = 0;
+		dev->me_client_presentation_num = 0;
+		dev->me_client_index = 0;
+		mei_allocate_me_clients_storage(dev);
+		dev->init_clients_state =
+			MEI_CLIENT_PROPERTIES_MESSAGE;
+		mei_host_client_properties(dev);
 		break;
 
 	case HOST_STOP_RES_CMD:
@@ -835,26 +827,24 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
 			struct mei_cl *cl,
 			struct mei_io_list *cmpl_list)
 {
-	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
+	if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_flow_control))) {
-		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_flow_control), sizeof(u32));
-		if (!mei_send_flow_control(dev, cl)) {
-			cl->status = -ENODEV;
-			cb_pos->information = 0;
-			list_move_tail(&cb_pos->cb_list,
-					&cmpl_list->mei_cb.cb_list);
-			return -ENODEV;
-		} else {
-			list_move_tail(&cb_pos->cb_list,
-					&dev->read_list.mei_cb.cb_list);
-		}
-	} else {
 		/* return the cancel routine */
 		list_del(&cb_pos->cb_list);
 		return -EBADMSG;
 	}
+	*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+		sizeof(struct hbm_flow_control), sizeof(u32));
+	if (!mei_send_flow_control(dev, cl)) {
+		cl->status = -ENODEV;
+		cb_pos->information = 0;
+		list_move_tail(&cb_pos->cb_list,
+				&cmpl_list->mei_cb.cb_list);
+		return -ENODEV;
+	}
 
+	list_move_tail(&cb_pos->cb_list,
+			&dev->read_list.mei_cb.cb_list);
 	return 0;
 }
 
@@ -874,26 +864,24 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
 			struct mei_cl *cl,
 			struct mei_io_list *cmpl_list)
 {
-	if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
+	if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
 			sizeof(struct hbm_client_connect_request))) {
-		cl->state = MEI_FILE_CONNECTING;
-		*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
-			sizeof(struct hbm_client_connect_request), sizeof(u32));
-		if (!mei_connect(dev, cl)) {
-			cl->status = -ENODEV;
-			cb_pos->information = 0;
-			list_del(&cb_pos->cb_list);
-			return -ENODEV;
-		} else {
-			list_move_tail(&cb_pos->cb_list,
-				&dev->ctrl_rd_list.mei_cb.cb_list);
-			cl->timer_count = MEI_CONNECT_TIMEOUT;
-		}
-	} else {
 		/* return the cancel routine */
 		list_del(&cb_pos->cb_list);
 		return -EBADMSG;
 	}
+	cl->state = MEI_FILE_CONNECTING;
+	*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
+		sizeof(struct hbm_client_connect_request), sizeof(u32));
+	if (!mei_connect(dev, cl)) {
+		cl->status = -ENODEV;
+		cb_pos->information = 0;
+		list_del(&cb_pos->cb_list);
+		return -ENODEV;
+	}
+	list_move_tail(&cb_pos->cb_list,
+			&dev->ctrl_rd_list.mei_cb.cb_list);
+	cl->timer_count = MEI_CONNECT_TIMEOUT;
 
 	return 0;
 }
-- 
1.7.9.2


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

* [PATCH 7/9] mei: reduce indentation by combining if blocks
  2012-02-24  1:38 Devin J. Pohly
                   ` (5 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 6/9] mei: reduce indentation with early returns Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 8/9] mei: reduce indentation in read_client_message Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 9/9] mei: reduce indentation in read_bus_message Devin J. Pohly
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   84 +++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index 541d018..6ae7a0e 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -1231,29 +1231,23 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
 		*slots -= dev->extra_write_index;
 		dev->extra_write_index = 0;
 	}
-	if (dev->mei_state == MEI_ENABLED) {
-		if (dev->wd_pending &&
+	if (dev->mei_state == MEI_ENABLED && dev->wd_pending &&
 			mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
-			if (mei_wd_send(dev))
-				dev_dbg(&dev->pdev->dev, "wd send failed.\n");
-			else
-				if (mei_flow_ctrl_reduce(dev, &dev->wd_cl))
-					return -ENODEV;
+		if (mei_wd_send(dev))
+			dev_dbg(&dev->pdev->dev, "wd send failed.\n");
+		else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl))
+			return -ENODEV;
 
-			dev->wd_pending = false;
+		dev->wd_pending = false;
 
-			if (dev->wd_timeout) {
-				*slots -= DIV_ROUND_UP(
-					sizeof(struct mei_msg_hdr) +
+		if (dev->wd_timeout) {
+			*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
 					MEI_START_WD_DATA_SIZE, sizeof(u32));
-				dev->wd_due_counter = 2;
-			} else {
-				*slots -= DIV_ROUND_UP(
-					sizeof(struct mei_msg_hdr) +
+			dev->wd_due_counter = 2;
+		} else {
+			*slots -= DIV_ROUND_UP(sizeof(struct mei_msg_hdr) +
 					MEI_WD_PARAMS_SIZE, sizeof(u32));
-				dev->wd_due_counter = 0;
-			}
-
+			dev->wd_due_counter = 0;
 		}
 	}
 	if (dev->stop)
@@ -1356,46 +1350,40 @@ void mei_timer(struct work_struct *work)
 
 	mutex_lock(&dev->device_lock);
 	if (dev->mei_state != MEI_ENABLED) {
-		if (dev->mei_state == MEI_INIT_CLIENTS) {
-			if (dev->init_clients_timer) {
-				if (--dev->init_clients_timer == 0) {
-					dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
-						dev->init_clients_state);
-					mei_reset(dev, 1);
-				}
-			}
+		if (dev->mei_state == MEI_INIT_CLIENTS &&
+				dev->init_clients_timer &&
+				--dev->init_clients_timer == 0) {
+			dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
+					dev->init_clients_state);
+			mei_reset(dev, 1);
 		}
 		goto out;
 	}
 	/* connect/disconnect timeouts */
 	list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
-		if (cl_pos->timer_count) {
-			if (--cl_pos->timer_count == 0) {
-				dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n");
-				mei_reset(dev, 1);
-				goto out;
-			}
+		if (cl_pos->timer_count && --cl_pos->timer_count == 0) {
+			dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n");
+			mei_reset(dev, 1);
+			goto out;
 		}
 	}
 
-	if (dev->iamthif_stall_timer) {
-		if (--dev->iamthif_stall_timer == 0) {
-			dev_dbg(&dev->pdev->dev, "reseting because of hang to amthi.\n");
-			mei_reset(dev, 1);
-			dev->iamthif_msg_buf_size = 0;
-			dev->iamthif_msg_buf_index = 0;
-			dev->iamthif_canceled = false;
-			dev->iamthif_ioctl = true;
-			dev->iamthif_state = MEI_IAMTHIF_IDLE;
-			dev->iamthif_timer = 0;
+	if (dev->iamthif_stall_timer && --dev->iamthif_stall_timer == 0) {
+		dev_dbg(&dev->pdev->dev, "reseting because of hang to amthi.\n");
+		mei_reset(dev, 1);
+		dev->iamthif_msg_buf_size = 0;
+		dev->iamthif_msg_buf_index = 0;
+		dev->iamthif_canceled = false;
+		dev->iamthif_ioctl = true;
+		dev->iamthif_state = MEI_IAMTHIF_IDLE;
+		dev->iamthif_timer = 0;
 
-			if (dev->iamthif_current_cb)
-				mei_free_cb_private(dev->iamthif_current_cb);
+		if (dev->iamthif_current_cb)
+			mei_free_cb_private(dev->iamthif_current_cb);
 
-			dev->iamthif_file_object = NULL;
-			dev->iamthif_current_cb = NULL;
-			mei_run_next_iamthif_cmd(dev);
-		}
+		dev->iamthif_file_object = NULL;
+		dev->iamthif_current_cb = NULL;
+		mei_run_next_iamthif_cmd(dev);
 	}
 
 	if (dev->iamthif_timer) {
-- 
1.7.9.2


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

* [PATCH 8/9] mei: reduce indentation in read_client_message
  2012-02-24  1:38 Devin J. Pohly
                   ` (6 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 7/9] mei: reduce indentation by combining if blocks Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  2012-02-24  1:38 ` [PATCH 9/9] mei: reduce indentation in read_bus_message Devin J. Pohly
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

Removes the empty check since that's handled by foreach.  Moves a big
chunk of code out of the foreach since it's followed by a break anyway.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   67 ++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index 6ae7a0e..f2c864e 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -193,51 +193,44 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,
 	unsigned char *buffer = NULL;
 
 	dev_dbg(&dev->pdev->dev, "start client msg\n");
-	if (list_empty(&dev->read_list.mei_cb.cb_list))
-		goto out;
 
 	list_for_each_entry_safe(cb_pos, cb_next,
 			&dev->read_list.mei_cb.cb_list, cb_list) {
 		cl = (struct mei_cl *)cb_pos->file_private;
-		if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) {
-			cl->reading_state = MEI_READING;
-			buffer = (unsigned char *)
-				(cb_pos->response_buffer.data +
-				cb_pos->information);
-
-			if (cb_pos->response_buffer.size <
-					mei_hdr->length + cb_pos->information) {
-				dev_dbg(&dev->pdev->dev, "message overflow.\n");
-				list_del(&cb_pos->cb_list);
-				return -ENOMEM;
-			}
-			if (buffer)
-				mei_read_slots(dev, buffer, mei_hdr->length);
+		if (cl && _mei_irq_thread_state_ok(cl, mei_hdr))
+			break;
+	}
 
-			cb_pos->information += mei_hdr->length;
-			if (mei_hdr->msg_complete) {
-				cl->status = 0;
-				list_del(&cb_pos->cb_list);
-				dev_dbg(&dev->pdev->dev,
-					"completed read host client = %d,"
-					"ME client = %d, "
-					"data length = %lu\n",
-					cl->host_client_id,
-					cl->me_client_id,
-					cb_pos->information);
-
-				*(cb_pos->response_buffer.data +
-					cb_pos->information) = '\0';
-				dev_dbg(&dev->pdev->dev, "cb_pos->res_buffer - %s\n",
-					cb_pos->response_buffer.data);
-				list_add_tail(&cb_pos->cb_list,
-					&complete_list->mei_cb.cb_list);
-			}
+	/* List empty, or client not found */
+	if (&cb_pos->cb_list == &dev->read_list.mei_cb.cb_list)
+		goto out;
 
-			break;
-		}
+	cl->reading_state = MEI_READING;
+	buffer = cb_pos->response_buffer.data + cb_pos->information;
 
+	if (cb_pos->response_buffer.size <
+			mei_hdr->length + cb_pos->information) {
+		dev_dbg(&dev->pdev->dev, "message overflow.\n");
+		list_del(&cb_pos->cb_list);
+		return -ENOMEM;
 	}
+	if (buffer)
+		mei_read_slots(dev, buffer, mei_hdr->length);
+
+	cb_pos->information += mei_hdr->length;
+	if (!mei_hdr->msg_complete)
+		goto out;
+
+	cl->status = 0;
+	list_del(&cb_pos->cb_list);
+	dev_dbg(&dev->pdev->dev, "completed read host client = %d, "
+		"ME client = %d, data length = %lu\n",
+		cl->host_client_id, cl->me_client_id, cb_pos->information);
+
+	cb_pos->response_buffer.data[cb_pos->information] = '\0';
+	dev_dbg(&dev->pdev->dev, "cb_pos->res_buffer - %s\n",
+		cb_pos->response_buffer.data);
+	list_add_tail(&cb_pos->cb_list, &complete_list->mei_cb.cb_list);
 
 out:
 	dev_dbg(&dev->pdev->dev, "message read\n");
-- 
1.7.9.2


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

* [PATCH 9/9] mei: reduce indentation in read_bus_message
  2012-02-24  1:38 Devin J. Pohly
                   ` (7 preceding siblings ...)
  2012-02-24  1:38 ` [PATCH 8/9] mei: reduce indentation in read_client_message Devin J. Pohly
@ 2012-02-24  1:38 ` Devin J. Pohly
  8 siblings, 0 replies; 12+ messages in thread
From: Devin J. Pohly @ 2012-02-24  1:38 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Devin J. Pohly

From: "Devin J. Pohly" <djpohly@gmail.com>

A chunk of code can be deindented by checking conditions early.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 drivers/staging/mei/interrupt.c |   29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c
index f2c864e..c2800ba 100644
--- a/drivers/staging/mei/interrupt.c
+++ b/drivers/staging/mei/interrupt.c
@@ -621,21 +621,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 	switch (*(u8 *) mei_msg) {
 	case HOST_START_RES_CMD:
 		version_res = (struct hbm_host_version_response *) mei_msg;
-		if (version_res->host_version_supported) {
-			dev->version.major_version = HBM_MAJOR_VERSION;
-			dev->version.minor_version = HBM_MINOR_VERSION;
-			if (dev->mei_state == MEI_INIT_CLIENTS &&
-					dev->init_clients_state ==
-					MEI_START_MESSAGE) {
-				dev->init_clients_timer = 0;
-				mei_host_enum_clients_message(dev);
-			} else {
-				dev->recvd_msg = false;
-				dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
-				mei_reset(dev, 1);
-				return;
-			}
-		} else {
+		if (!version_res->host_version_supported) {
 			dev->version = version_res->me_max_version;
 			/* send stop message */
 			mei_hdr->host_addr = 0;
@@ -657,6 +643,19 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
 			return;
 		}
 
+		dev->version.major_version = HBM_MAJOR_VERSION;
+		dev->version.minor_version = HBM_MINOR_VERSION;
+		if (dev->mei_state != MEI_INIT_CLIENTS ||
+					dev->init_clients_state !=
+					MEI_START_MESSAGE) {
+			dev->recvd_msg = false;
+			dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
+			mei_reset(dev, 1);
+			return;
+		}
+		dev->init_clients_timer = 0;
+		mei_host_enum_clients_message(dev);
+
 		dev->recvd_msg = true;
 		dev_dbg(&dev->pdev->dev, "host start response message received.\n");
 		break;
-- 
1.7.9.2


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

* Re: [PATCH 1/9] mei: cosmetic cleanup in interrupt.c
  2012-02-24  1:38 ` [PATCH 1/9] mei: cosmetic cleanup in interrupt.c Devin J. Pohly
@ 2012-02-24  2:51   ` Greg KH
  0 siblings, 0 replies; 12+ messages in thread
From: Greg KH @ 2012-02-24  2:51 UTC (permalink / raw)
  To: Devin J. Pohly; +Cc: linux-kernel

On Thu, Feb 23, 2012 at 08:38:48PM -0500, Devin J. Pohly wrote:
> From: "Devin J. Pohly" <djpohly@gmail.com>
> 
> Tabs, spaces, long lines, lines that could be combined, superfluous
> parentheses, etc.  Also uses DIV_ROUND_UP and sizeof(*ptr) where
> appropriate.

That's a lot of different things all in one patch.

Please only do one thing per patch.

Also, please cc: the maintainers of this patch, I'm sure they would also
have comments on it, use the scripts/get_maintainer.pl tool to figure
out who to send it to (hint, you also should copy the driverdevel
mailing list.)

Care to redo these please?

thanks,

greg k-h

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

* Re: [PATCH 4/9] mei: return values are -Exxx, not ~Exxx!
  2012-02-24  1:38 ` [PATCH 4/9] mei: return values are -Exxx, not ~Exxx! Devin J. Pohly
@ 2012-02-27 16:35   ` Tomas Winkler
  0 siblings, 0 replies; 12+ messages in thread
From: Tomas Winkler @ 2012-02-27 16:35 UTC (permalink / raw)
  To: Devin J. Pohly, Greg KH; +Cc: linux-kernel, devel

On Fri, Feb 24, 2012 at 3:38 AM, Devin J. Pohly <djpohly@gmail.com> wrote:
> From: "Devin J. Pohly" <djpohly@gmail.com>
>
> There's no way this is what was intended! :)
>
> Signed-off-by: Devin J. Pohly <djpohly@gmail.com>

Good catch but  can you please resend it out of  the series with maybe
some more informative commit message.

Appreciated
Tomas

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

end of thread, other threads:[~2012-02-27 16:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-24  1:38 Devin J. Pohly
2012-02-24  1:38 ` [PATCH 1/9] mei: cosmetic cleanup in interrupt.c Devin J. Pohly
2012-02-24  2:51   ` Greg KH
2012-02-24  1:38 ` [PATCH 2/9] mei: factor some bits of code outside if blocks Devin J. Pohly
2012-02-24  1:38 ` [PATCH 3/9] mei: more idiomatic variable/label usage Devin J. Pohly
2012-02-24  1:38 ` [PATCH 4/9] mei: return values are -Exxx, not ~Exxx! Devin J. Pohly
2012-02-27 16:35   ` Tomas Winkler
2012-02-24  1:38 ` [PATCH 5/9] mei: remove indentation where else follows return Devin J. Pohly
2012-02-24  1:38 ` [PATCH 6/9] mei: reduce indentation with early returns Devin J. Pohly
2012-02-24  1:38 ` [PATCH 7/9] mei: reduce indentation by combining if blocks Devin J. Pohly
2012-02-24  1:38 ` [PATCH 8/9] mei: reduce indentation in read_client_message Devin J. Pohly
2012-02-24  1:38 ` [PATCH 9/9] mei: reduce indentation in read_bus_message Devin J. Pohly

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.