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(-)
PATCH 1/9 mei: cosmetic cleanup in interrupt.c
From: "Devin J. Pohly" <[email protected]>
Tabs, spaces, long lines, lines that could be combined, superfluous parentheses, etc. Also uses DIV_ROUND_UP and sizeof(*ptr) where appropriate.
--- 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(-)
drivers/staging/mei/init.c +1 -1
@@ -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. */
drivers/staging/mei/interrupt.c +110 -129
636 lines not on this page · raw message
drivers/staging/mei/mei_dev.h +2 -1
@@ -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);
drivers/staging/mei/mei_version.h +3 -3
@@ -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
drivers/staging/mei/wd.c +15 -8
@@ -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; } }
Signature · 1 line
1.7.9.2
Greg KH
maintainerRe: [PATCH 1/9] mei: cosmetic cleanup in interrupt.c
Quoted 5 lines · Devin J. Pohly
From: "Devin J. Pohly" <[email protected]>
Tabs, spaces, long lines, lines that could be combined, superfluous parentheses, etc. Also uses
DIV_ROUND_UPandsizeof(*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
PATCH 2/9 mei: factor some bits of code outside if blocks
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
--- drivers/staging/mei/interrupt.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/staging/mei/interrupt.c +4 -11
@@ -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);
Signature · 1 line
1.7.9.2
PATCH 3/9 mei: more idiomatic variable/label usage
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
Rename rets -> ret, and quit -> out. Also, use return instead of goto end when end is just a return anyway.
--- drivers/staging/mei/interrupt.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
drivers/staging/mei/interrupt.c +13 -18
@@ -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);
Signature · 1 line
1.7.9.2
PATCH 4/9 mei: return values are -Exxx, not ~Exxx!
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
There's no way this is what was intended! :)
--- drivers/staging/mei/interrupt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/mei/interrupt.c +1 -1
@@ -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" );
Signature · 1 line
1.7.9.2
Re: [PATCH 4/9] mei: return values are -Exxx, not ~Exxx!
Quoted 5 lines · Devin J. Pohly
From: "Devin J. Pohly" <[email protected]>
There's no way this is what was intended! :)
Signed-off-by Devin J. Pohly <[email protected]>
Good catch but can you please resend it out of the series with maybe some more informative commit message.
Appreciated
Tomas
PATCH 5/9 mei: remove indentation where else follows return
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
If a function returns early as the last statement of an if block, the "else" is pretty much implied.
--- drivers/staging/mei/interrupt.c | 58 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/staging/mei/interrupt.c +27 -31
@@ -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 ];
Signature · 1 line
1.7.9.2
PATCH 6/9 mei: reduce indentation with early returns
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
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.
--- drivers/staging/mei/interrupt.c | 352 +++++++++++++++++++-------------------- 1 file changed, 170 insertions(+), 182 deletions(-)
drivers/staging/mei/interrupt.c +170 -182
@@ -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 ; }
Signature · 1 line
1.7.9.2
PATCH 7/9 mei: reduce indentation by combining if blocks
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
--- drivers/staging/mei/interrupt.c | 84 +++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 48 deletions(-)
drivers/staging/mei/interrupt.c +36 -48
@@ -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) {
Signature · 1 line
1.7.9.2
PATCH 8/9 mei: reduce indentation in read_client_message
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
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.
--- drivers/staging/mei/interrupt.c | 67 ++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 37 deletions(-)
drivers/staging/mei/interrupt.c +30 -37
@@ -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" );
Signature · 1 line
1.7.9.2
PATCH 9/9 mei: reduce indentation in read_bus_message
In reply to Devin J. PohlyFrom: "Devin J. Pohly" <[email protected]>
A chunk of code can be deindented by checking conditions early.
--- drivers/staging/mei/interrupt.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/staging/mei/interrupt.c +14 -15
@@ -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 ;
Signature · 1 line
1.7.9.2