mei: rename mei_cl_cb.information to mei_cl_cb.buf_idx
Subsystems (2)
PATCH 1/6 mei: rename mei_cl_cb.information to mei_cl_cb.buf_idx
rename 'information' member of the struct mei_cl_cb to more self-descriptive 'buf_idx'
--- drivers/misc/mei/interrupt.c | 43 ++++++++++++++++++++--------------------- drivers/misc/mei/iorw.c | 17 +++++++-------- drivers/misc/mei/main.c | 33 ++++++++++++++----------------- drivers/misc/mei/mei_dev.h | 2 +- 4 files changed, 45 insertions(+), 50 deletions(-)
drivers/misc/mei/interrupt.c +21 -22
@@ -149,7 +149,7 @@ 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->buf_idx = dev->iamthif_msg_buf_index; cb->read_time = jiffies;if (dev->iamthif_ioctl && cl == &dev->iamthif_cl) {/* found the iamthif cb */
@@ -205,10 +205,10 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_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 = cb_pos->response_buffer.data + cb_pos->information; + buffer = cb_pos->response_buffer.data + cb_pos->buf_idx;if (cb_pos->response_buffer.size < - mei_hdr->length + cb_pos->information) { + mei_hdr->length + cb_pos->buf_idx) {dev_dbg (&dev->pdev->dev,"message overflow.\n" );list_del (&cb_pos->cb_list);return -ENOMEM ;
@@ -216,7 +216,7 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,if (buffer)mei_read_slots (dev, buffer, mei_hdr->length); - cb_pos->information += mei_hdr->length; + cb_pos->buf_idx += mei_hdr->length;if (mei_hdr->msg_complete) { cl->status =0 ;list_del (&cb_pos->cb_list);
@@ -224,7 +224,8 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list,"completed read H cl = %d, ME cl = %d, length = %lu\n" , cl->host_client_id, cl->me_client_id, - cb_pos->information); + cb_pos->buf_idx); +list_add_tail (&cb_pos->cb_list, &complete_list->mei_cb.cb_list); }
@@ -300,14 +301,14 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,if (mei_disconnect (dev, cl)) { cl->status =0 ; - cb_pos->information =0 ; + cb_pos->buf_idx =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 ; + cb_pos->buf_idx =0 ;list_move_tail (&cb_pos->cb_list, &dev->ctrl_rd_list.mei_cb.cb_list); cl->timer_count =MEI_CONNECT_TIMEOUT ;
@@ -834,7 +835,7 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,if (mei_send_flow_control (dev, cl)) { cl->status = -ENODEV ; - cb_pos->information =0 ; + cb_pos->buf_idx =0 ;list_move_tail (&cb_pos->cb_list, &cmpl_list->mei_cb.cb_list);return -ENODEV ; }
@@ -871,7 +872,7 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, *slots -=mei_data2slots (sizeof (struct hbm_client_connect_request ));if (mei_connect (dev, cl)) { cl->status = -ENODEV ; - cb_pos->information =0 ; + cb_pos->buf_idx =0 ;list_del (&cb_pos->cb_list);return -ENODEV ; }else {
@@ -901,28 +902,26 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,struct mei_msg_hdr *mei_hdr;if ((*slots *sizeof (u32)) >= (sizeof (struct mei_msg_hdr ) + - (cb_pos->request_buffer.size - - cb_pos->information))) { + (cb_pos->request_buffer.size - cb_pos->buf_idx))) { 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 = cb_pos->request_buffer.size - - cb_pos->information; + mei_hdr->length = cb_pos->request_buffer.size - cb_pos->buf_idx; mei_hdr->msg_complete =1 ; mei_hdr->reserved =0 ;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,"cb_pos->buf_idx =%lu\n" , + cb_pos->buf_idx);dev_dbg (&dev->pdev->dev,"mei_hdr->length =%d\n" , mei_hdr->length); *slots -=mei_data2slots (mei_hdr->length);if (mei_write_message (dev, mei_hdr, (unsigned char *) (cb_pos->request_buffer.data + - cb_pos->information), + cb_pos->buf_idx), mei_hdr->length)) { cl->status = -ENODEV ; list_move_tail(&cb_pos->cb_list,
@@ -932,7 +931,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,if (mei_flow_ctrl_reduce (dev, cl))return -ENODEV ; cl->status =0 ; - cb_pos->information += mei_hdr->length; + cb_pos->buf_idx += mei_hdr->length;list_move_tail (&cb_pos->cb_list, &dev->write_waiting_list.mei_cb.cb_list); }
@@ -949,21 +948,21 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,if (mei_write_message (dev, mei_hdr, (unsigned char *) (cb_pos->request_buffer.data + - cb_pos->information), + cb_pos->buf_idx), mei_hdr->length)) { cl->status = -ENODEV ;list_move_tail (&cb_pos->cb_list, &cmpl_list->mei_cb.cb_list);return -ENODEV ; }else { - cb_pos->information += mei_hdr->length; + cb_pos->buf_idx += 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,"cb_pos->buf_idx =%lu\n" , + cb_pos->buf_idx);dev_dbg (&dev->pdev->dev,"mei_hdr->length =%d\n" , mei_hdr->length); }
@@ -1018,7 +1017,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,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; + cb_pos->buf_idx = dev->iamthif_msg_buf_index; cl->status =0 ; dev->iamthif_state =MEI_IAMTHIF_FLOW_CONTROL ; dev->iamthif_flow_control_pending = true;
drivers/misc/mei/iorw.c +8 -9
@@ -346,9 +346,9 @@ int amthi_read(struct mei_device *dev, struct file *file, } }/* if the whole message will fit remove it from the list */ -if (cb->information >= *offset && length >= (cb->information - *offset)) +if (cb->buf_idx >= *offset && length >= (cb->buf_idx - *offset))list_del (&cb->cb_list); -else if (cb->information >0 && cb->information <= *offset) { +else if (cb->buf_idx >0 && cb->buf_idx <= *offset) {/* end of the message has been reached */ list_del (&cb->cb_list); rets =0 ;
@@ -360,18 +360,17 @@ int amthi_read(struct mei_device *dev, struct file *file,dev_dbg (&dev->pdev->dev,"amthi cb->response_buffer size - %d\n" , cb->response_buffer.size); -dev_dbg (&dev->pdev->dev,"amthi cb->information - %lu\n" , - cb->information); +dev_dbg (&dev->pdev->dev,"amthi cb->buf_idx - %lu\n" , cb->buf_idx);/* length is being turncated to PAGE_SIZE, however, -* the information may be longer */ - length =min_t (size_t, length, (cb->information - *offset)); +* the buf_idx may point beyond */ + length =min_t (size_t, length, (cb->buf_idx - *offset));if (copy_to_user (ubuf, cb->response_buffer.data + *offset, length)) rets = -EFAULT ;else { rets = length; -if ((*offset + length) < cb->information) { +if ((*offset + length) < cb->buf_idx) { *offset += length; goto out; }
@@ -432,8 +431,8 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl) }dev_dbg (&dev->pdev->dev,"allocation call back data success.\n" ); cb->major_file_operations =MEI_READ ; -/* make sure information is zero before we start */ - cb->information =0 ; +/* make sure buffer index is zero before we start */ + cb->buf_idx =0 ; cb->file_private = (void *) cl; cl->read_cb = cb;if (dev->mei_host_buffer_is_empty) {
drivers/misc/mei/main.c +15 -18
@@ -415,16 +415,15 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, goto out; } -if (cl->read_cb && cl->read_cb->information > *offset) { +if (cl->read_cb && cl->read_cb->buf_idx > *offset) { cb = cl->read_cb; goto copy_buffer; - }else if (cl->read_cb && cl->read_cb->information >0 && - cl->read_cb->information <= *offset) { + }else if (cl->read_cb && cl->read_cb->buf_idx >0 && + cl->read_cb->buf_idx <= *offset) { cb = cl->read_cb; rets =0 ; goto free; - }else if ((!cl->read_cb || !cl->read_cb->information) && - *offset >0 ) { + }else if ((!cl->read_cb || !cl->read_cb->buf_idx) && *offset >0 ) {/*Offset needs to be cleaned for contiguous reads*/ *offset =0 ; rets =0 ;
@@ -481,16 +480,15 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, copy_buffer:dev_dbg (&dev->pdev->dev,"cb->response_buffer size - %d\n" , cb->response_buffer.size); -dev_dbg (&dev->pdev->dev,"cb->information - %lu\n" , - cb->information); -if (length ==0 || ubuf ==NULL || *offset > cb->information) { +dev_dbg (&dev->pdev->dev,"cb->buf_idx - %lu\n" , cb->buf_idx); +if (length ==0 || ubuf ==NULL || *offset > cb->buf_idx) { rets = -EMSGSIZE ; goto free; } -/* length is being truncated to PAGE_SIZE, however, */ -/* information size may be longer */ - length =min_t (size_t, length, (cb->information - *offset)); +/* length is being truncated to PAGE_SIZE, +* however buf_idx may point beyond that */ + length =min_t (size_t, length, cb->buf_idx - *offset);if (copy_to_user (ubuf, cb->response_buffer.data + *offset, length)) { rets = -EFAULT ;
@@ -499,7 +497,7 @@ copy_buffer: rets = length; *offset += length; -if ((unsigned long )*offset < cb->information) +if ((unsigned long )*offset < cb->buf_idx) goto out; free:
@@ -637,7 +635,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, write_cb->response_buffer.size = dev->iamthif_mtu; write_cb->major_file_operations =MEI_IOCTL ; - write_cb->information =0 ; + write_cb->buf_idx =0 ; write_cb->request_buffer.size = length;if (dev->iamthif_cl.state !=MEI_FILE_CONNECTED ) { rets = -ENODEV ;
@@ -668,9 +666,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, } write_cb->major_file_operations =MEI_WRITE ; -/* make sure information is zero before we start */ - - write_cb->information =0 ; +/* make sure buffer index is zero before we start */ + write_cb->buf_idx =0 ; write_cb->request_buffer.size = length; dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
@@ -719,7 +716,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto unlock_dev; } cl->writing_state =MEI_WRITING ; - write_cb->information = mei_hdr.length; + write_cb->buf_idx = mei_hdr.length;if (mei_hdr.msg_complete) {if (mei_flow_ctrl_reduce (dev, cl)) { rets = -ENODEV ;
@@ -734,7 +731,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, }else { - write_cb->information =0 ; + write_cb->buf_idx =0 ; cl->writing_state =MEI_WRITING ;list_add_tail (&write_cb->cb_list, &dev->write_list.mei_cb.cb_list);
drivers/misc/mei/mei_dev.h +1 -1
@@ -149,7 +149,7 @@ struct mei_cl_cb {void *file_private;struct mei_message_data request_buffer;struct mei_message_data response_buffer; -unsigned long information; +unsigned long buf_idx;unsigned long read_time;struct file *file_object; };
Signature · 1 line
1.7.4.4
PATCH 3/6 mei: mei_write: revamp error path handling
1. unify common amt and regular error path and use it early in the function
2. fix indentation
3. propagate error code directly from copy_from_user
4. print out errors using dev_err instead of dev_dbg
--- drivers/misc/mei/main.c | 75 +++++++++++++++++------------------------------ 1 files changed, 27 insertions(+), 48 deletions(-)
drivers/misc/mei/main.c +27 -48
@@ -621,10 +621,26 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,mutex_lock (&dev->device_lock);if (dev->dev_state !=MEI_DEV_ENABLED ) { -mutex_unlock (&dev->device_lock); -return -ENODEV ; + rets = -ENODEV ; + goto unlock_dev; } + i =mei_me_cl_by_id (dev, cl->me_client_id); +if (i <0 ) { + rets = -ENODEV ; + goto unlock_dev; + } +if (length > dev->me_clients[i].props.max_msg_length || length <=0 ) { + rets = -EMSGSIZE ; + goto unlock_dev; + } + +if (cl->state !=MEI_FILE_CONNECTED ) { + rets = -ENODEV ; +dev_err (&dev->pdev->dev,"host client = %d, is not connected to ME client = %d" , + cl->host_client_id, cl->me_client_id); + goto unlock_dev; + }if (cl == &dev->iamthif_cl) { write_cb =find_amthi_read_list_entry (dev, file);
@@ -633,11 +649,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,msecs_to_jiffies (IAMTHIF_READ_TIMER );if (time_after (jiffies, timeout) || - cl->reading_state ==MEI_READ_COMPLETE ) { - *offset =0 ; -list_del (&write_cb->cb_list); -mei_free_cb_private (write_cb); - write_cb =NULL ; + cl->reading_state ==MEI_READ_COMPLETE ) { + *offset =0 ; +list_del (&write_cb->cb_list); +mei_free_cb_private (write_cb); + write_cb =NULL ; } } }
@@ -670,8 +686,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,dev_dbg (&dev->pdev->dev,"cb request size = %zd\n" , length); - rets = -EFAULT ; -if (copy_from_user (write_cb->request_buffer.data, ubuf, length)) + rets =copy_from_user (write_cb->request_buffer.data, ubuf, length); +if (rets) goto unlock_dev; cl->sm_state =0 ;
@@ -685,29 +701,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, cl->sm_state |=MEI_WD_STATE_INDEPENDENCE_MSG_SENT ;if (cl == &dev->iamthif_cl) { -if (dev->dev_state !=MEI_DEV_ENABLED ) { - rets = -ENODEV ; - goto unlock_dev; - } - i =mei_me_cl_by_id (dev, dev->iamthif_cl.me_client_id); -if (i <0 ) { - rets = -ENODEV ; - goto unlock_dev; - } -if (length > dev->me_clients[i].props.max_msg_length || - length <=0 ) { - rets = -EMSGSIZE ; - goto unlock_dev; - } rets =mei_io_cb_alloc_resp_buf (write_cb, dev->iamthif_mtu);if (rets) goto unlock_dev; write_cb->major_file_operations =MEI_IOCTL ; -if (dev->iamthif_cl.state !=MEI_FILE_CONNECTED ) { - rets = -ENODEV ; - goto unlock_dev; - }if (!list_empty (&dev->amthi_cmd_list.mei_cb.cb_list) || dev->iamthif_state !=MEI_IAMTHIF_IDLE ) {
@@ -716,43 +714,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,dev_dbg (&dev->pdev->dev,"add amthi cb to amthi cmd waiting list\n" );list_add_tail (&write_cb->cb_list, &dev->amthi_cmd_list.mei_cb.cb_list); - rets = length; }else {dev_dbg (&dev->pdev->dev,"call amthi write\n" ); rets =amthi_write (dev, write_cb);if (rets) { -dev_dbg (&dev->pdev->dev,"amthi write failed with status = %d\n" , +dev_err (&dev->pdev->dev,"amthi write failed with status = %d\n" , rets); goto unlock_dev; } - rets = length; }mutex_unlock (&dev->device_lock); -return rets; +return length; } write_cb->major_file_operations =MEI_WRITE ;dev_dbg (&dev->pdev->dev,"host client = %d, ME client = %d\n" , cl->host_client_id, cl->me_client_id); -if (cl->state !=MEI_FILE_CONNECTED ) { - rets = -ENODEV ; -dev_dbg (&dev->pdev->dev,"host client = %d, is not connected to ME client = %d" , - cl->host_client_id, - cl->me_client_id); - goto unlock_dev; - } - i =mei_me_cl_by_id (dev, cl->me_client_id); -if (i <0 ) { - rets = -ENODEV ; - goto unlock_dev; - } -if (length > dev->me_clients[i].props.max_msg_length || length <=0 ) { - rets = -EINVAL ; - goto unlock_dev; - } - rets =mei_flow_ctrl_creds (dev, cl);if (rets <0 ) goto unlock_dev;
Signature · 1 line
1.7.4.4
PATCH 4/6 mei: kill usless struct mei_io_list
In reply to Tomas Winklerkill useless mei_io_list list wrapper and use directly struct mei_cl_cb mei_cb which was its only member for managing io queues
--- drivers/misc/mei/init.c | 29 ++------- drivers/misc/mei/interrupt.c | 134 ++++++++++++++++++------------------------ drivers/misc/mei/iorw.c | 34 +++++------ drivers/misc/mei/main.c | 43 ++++++-------- drivers/misc/mei/mei_dev.h | 32 ++++++----- 5 files changed, 116 insertions(+), 156 deletions(-)
drivers/misc/mei/init.c +7 -22
@@ -48,34 +48,22 @@ const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac, 0x81, 0x4c);/** -* mei_io_list_init - Sets up a queue list. -* -* @list: An instance io list structure -* @dev: the device structure -*/ -void mei_io_list_init (struct mei_io_list *list) -{ -/* initialize our queue list */ -INIT_LIST_HEAD (&list->mei_cb.cb_list); -} - -/** * mei_io_list_flush - removes list entry belonging to cl. * * @list: An instance of our list structure * @cl: private data of the file object */ -void mei_io_list_flush (struct mei_io_list *list,struct mei_cl *cl) +void mei_io_list_flush (struct mei_cl_cb *list,struct mei_cl *cl) {struct mei_cl_cb *pos;struct mei_cl_cb *next; -list_for_each_entry_safe (pos, next, &list->mei_cb.cb_list, cb_list) { +list_for_each_entry_safe (pos, next, &list->list, list) {if (pos->file_private) {struct mei_cl *cl_tmp; cl_tmp = (struct mei_cl *)pos->file_private;if (mei_cl_cmp_id (cl, cl_tmp)) -list_del (&pos->cb_list); +list_del (&pos->list); } } }
@@ -351,9 +339,8 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) } }/* remove all waiting requests */ -list_for_each_entry_safe (cb_pos, cb_next, - &dev->write_list.mei_cb.cb_list, cb_list) { -list_del (&cb_pos->cb_list); +list_for_each_entry_safe (cb_pos, cb_next, &dev->write_list.list, list) { +list_del (&cb_pos->list);mei_free_cb_private (cb_pos); } }
@@ -685,7 +672,7 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)if (!cb)return -ENOMEM ; -INIT_LIST_HEAD (&cb->cb_list); +mei_io_list_init (cb); cb->file_private = cl; cb->major_file_operations =MEI_CLOSE ;if (dev->mei_host_buffer_is_empty) {
@@ -696,11 +683,9 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl) goto free; }mdelay (10 );/* Wait for hardware disconnection ready */ -list_add_tail (&cb->cb_list, &dev->ctrl_rd_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->ctrl_rd_list.list); }else {dev_dbg (&dev->pdev->dev,"add disconnect cb to control write list\n" ); -list_add_tail (&cb->cb_list, - &dev->ctrl_wr_list.mei_cb.cb_list); }mutex_unlock (&dev->device_lock);
drivers/misc/mei/interrupt.c +58 -76
396 lines not on this page · raw message
drivers/misc/mei/iorw.c +14 -20
@@ -104,7 +104,7 @@ int mei_ioctl_connect_client(struct file *file, rets = -ENOMEM ; goto end; } -INIT_LIST_HEAD (&cb->cb_list); +mei_io_list_init (cb); cb->major_file_operations =MEI_IOCTL ;
@@ -193,9 +193,7 @@ int mei_ioctl_connect_client(struct file *file,dev_dbg (&dev->pdev->dev,"Sending connect message - succeeded\n" ); cl->timer_count =MEI_CONNECT_TIMEOUT ; cb->file_private = cl; -list_add_tail (&cb->cb_list, - &dev->ctrl_rd_list.mei_cb. - cb_list); +list_add_tail (&cb->list, &dev->ctrl_rd_list.list); }
@@ -203,8 +201,7 @@ int mei_ioctl_connect_client(struct file *file,dev_dbg (&dev->pdev->dev,"Queuing the connect request due to device busy\n" ); cb->file_private = cl;dev_dbg (&dev->pdev->dev,"add connect cb to control write list.\n" ); -list_add_tail (&cb->cb_list, - &dev->ctrl_wr_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->ctrl_wr_list.list); }mutex_unlock (&dev->device_lock); err = wait_event_timeout(dev->wait_recvd_msg,
@@ -255,7 +252,7 @@ struct mei_cl_cb *find_amthi_read_list_entry(struct mei_cl_cb *next =NULL ;list_for_each_entry_safe (pos, next, - &dev->amthi_read_complete_list.mei_cb.cb_list, cb_list) { + &dev->amthi_read_complete_list.list, list) { cl_temp = (struct mei_cl *)pos->file_private;if (cl_temp && cl_temp == &dev->iamthif_cl && pos->file_object == file)
@@ -340,17 +337,17 @@ int amthi_read(struct mei_device *dev, struct file *file,if (time_after (jiffies, timeout)) {dev_dbg (&dev->pdev->dev,"amthi Time out\n" );/* 15 sec for the message has expired */ -list_del (&cb->cb_list); +list_del (&cb->list); rets = -ETIMEDOUT ; goto free; } }/* if the whole message will fit remove it from the list */ if (cb->buf_idx >= *offset && length >= (cb->buf_idx - *offset)) -list_del (&cb->cb_list); +list_del (&cb->list);else if (cb->buf_idx >0 && cb->buf_idx <= *offset) {/* end of the message has been reached */ -list_del (&cb->cb_list); +list_del (&cb->list); rets =0 ; goto free; }
@@ -441,9 +438,9 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl) rets = -ENODEV ; goto unlock; } -list_add_tail (&cb->cb_list, &dev->read_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->read_list.list); }else { -list_add_tail (&cb->cb_list, &dev->ctrl_wr_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->ctrl_wr_list.list); }return rets; unlock:
@@ -510,13 +507,11 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb)dev_dbg (&dev->pdev->dev,"add amthi cb to write waiting list\n" ); dev->iamthif_current_cb = cb; dev->iamthif_file_object = cb->file_object; -list_add_tail (&cb->cb_list, - &dev->write_waiting_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->write_waiting_list.list); }else {dev_dbg (&dev->pdev->dev,"message does not complete, " "so add amthi cb to write list.\n" ); -list_add_tail (&cb->cb_list, - &dev->write_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->write_list.list); } }else {if (!(dev->mei_host_buffer_is_empty))
@@ -524,7 +519,7 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb)dev_dbg (&dev->pdev->dev,"No flow control credentials, " "so add iamthif cb to write list.\n" ); -list_add_tail (&cb->cb_list, &dev->write_list.mei_cb.cb_list); +list_add_tail (&cb->list, &dev->write_list.list); }return 0 ; }
@@ -556,9 +551,8 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev)dev_dbg (&dev->pdev->dev,"complete amthi cmd_list cb.\n" ); -list_for_each_entry_safe (pos, next, - &dev->amthi_cmd_list.mei_cb.cb_list, cb_list) { -list_del (&pos->cb_list); +list_for_each_entry_safe (pos, next, &dev->amthi_cmd_list.list, list) { +list_del (&pos->list); cl_tmp = (struct mei_cl *)pos->file_private;if (cl_tmp && cl_tmp == &dev->iamthif_cl) {
drivers/misc/mei/main.c +19 -24
126 lines not on this page · raw message
drivers/misc/mei/mei_dev.h +18 -14
@@ -144,7 +144,7 @@ struct mei_message_data {struct mei_cl_cb { -struct list_head cb_list; +struct list_head list;enum mei_cb_major_types major_file_operations;void *file_private;struct mei_message_data request_buffer;
@@ -175,10 +175,6 @@ struct mei_cl {struct mei_cl_cb *read_cb; }; -struct mei_io_list { -struct mei_cl_cb mei_cb; -}; -/** * struct mei_deive - MEI private device struct * @hbuf_depth - depth of host(write) buffer
@@ -189,15 +185,15 @@ struct mei_device {* lists of queues */ /* array of pointers to aio lists */ -struct mei_io_list read_list;/* driver read queue */ -struct mei_io_list write_list;/* driver write queue */ -struct mei_io_list write_waiting_list;/* write waiting queue */ -struct mei_io_list ctrl_wr_list;/* managed write IOCTL list */ -struct mei_io_list ctrl_rd_list;/* managed read IOCTL list */ -struct mei_io_list amthi_cmd_list;/* amthi list for cmd waiting */ +struct mei_cl_cb read_list;/* driver read queue */ +struct mei_cl_cb write_list;/* driver write queue */ +struct mei_cl_cb write_waiting_list;/* write waiting queue */ +struct mei_cl_cb ctrl_wr_list;/* managed write IOCTL list */ +struct mei_cl_cb ctrl_rd_list;/* managed read IOCTL list */ +struct mei_cl_cb amthi_cmd_list;/* amthi list for cmd waiting */ /* driver managed amthi list for reading completed amthi cmd data */ -struct mei_io_list amthi_read_complete_list; +struct mei_cl_cb amthi_read_complete_list;/* * list of files */
@@ -297,8 +293,16 @@ int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);/* * MEI IO List Functions */ -void mei_io_list_init (struct mei_io_list *list); -void mei_io_list_flush (struct mei_io_list *list,struct mei_cl *cl); +/** +* mei_io_list_init - Sets up a queue list. +* +* @list: An instance cl callback structure +*/ +static inline void mei_io_list_init (struct mei_cl_cb *list) +{ +INIT_LIST_HEAD (&list->list); +} +void mei_io_list_flush (struct mei_cl_cb *list,struct mei_cl *cl);/* * MEI ME Client Functions
Signature · 1 line
1.7.4.4
PATCH 6/6 mei: use mei_io_cb_ warppers also for control flows
In reply to Tomas Winklermove the mei_io_cb_ wrappers to to iorw.c for global use and use them also for handling control flows
--- drivers/misc/mei/init.c | 4 +- drivers/misc/mei/iorw.c | 120 +++++++++++++++++++++++++++++++++---------- drivers/misc/mei/main.c | 78 ---------------------------- drivers/misc/mei/mei_dev.h | 4 ++ 4 files changed, 97 insertions(+), 109 deletions(-)
drivers/misc/mei/init.c +1 -3
@@ -668,12 +668,10 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)if (cl->state !=MEI_FILE_DISCONNECTING )return 0 ; - cb =kzalloc (sizeof (struct mei_cl_cb ),GFP_KERNEL ); + cb =mei_io_cb_init (cl,NULL );if (!cb)return -ENOMEM ; -mei_io_list_init (cb); - cb->file_private = cl; cb->major_file_operations =MEI_CLOSE ;if (dev->mei_host_buffer_is_empty) { dev->mei_host_buffer_is_empty = false;
drivers/misc/mei/iorw.c +92 -28
182 lines not on this page · raw message
drivers/misc/mei/main.c +0 -78
84 lines not on this page · raw message
drivers/misc/mei/mei_dev.h +4 -0
@@ -293,7 +293,11 @@ int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);/* * MEI IO Functions */ +struct mei_cl_cb *mei_io_cb_init (struct mei_cl *cl,struct file *fp);void mei_io_cb_free (struct mei_cl_cb *priv_cb); +int mei_io_cb_alloc_req_buf (struct mei_cl_cb *cb,size_t length); +int mei_io_cb_alloc_resp_buf (struct mei_cl_cb *cb,size_t length); +/** * mei_io_list_init - Sets up a queue list.
Signature · 1 line
1.7.4.4
PATCH 5/6 mei: rename mei_free_cb_private to mei_io_cb_free
In reply to Tomas Winkler1. cb_private was an old name that we depriacated in earlier cleanups
2. we also group the funcion declaration with other _io_ functions
3. Don't check cb for NULL as mei_io_cb_free is NULL safe
--- drivers/misc/mei/init.c | 4 ++-- drivers/misc/mei/interrupt.c | 12 +++++------- drivers/misc/mei/iorw.c | 35 ++++++++++++++++++----------------- drivers/misc/mei/main.c | 14 +++++++------- drivers/misc/mei/mei_dev.h | 5 +++-- 5 files changed, 35 insertions(+), 35 deletions(-)
drivers/misc/mei/init.c +2 -2
@@ -341,7 +341,7 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)/* remove all waiting requests */ list_for_each_entry_safe (cb_pos, cb_next, &dev->write_list.list, list) {list_del (&cb_pos->list); -mei_free_cb_private (cb_pos); +mei_io_cb_free (cb_pos); } }
@@ -713,7 +713,7 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)mei_io_list_flush (&dev->ctrl_rd_list, cl);mei_io_list_flush (&dev->ctrl_wr_list, cl); free: -mei_free_cb_private (cb); +mei_io_cb_free (cb);return rets; }
drivers/misc/mei/interrupt.c +5 -7
@@ -58,7 +58,7 @@ irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id)static void _mei_cmpl (struct mei_cl *cl,struct mei_cl_cb *cb_pos) {if (cb_pos->major_file_operations ==MEI_WRITE ) { -mei_free_cb_private (cb_pos); +mei_io_cb_free (cb_pos); cb_pos =NULL ; cl->writing_state =MEI_WRITE_COMPLETE ;if (waitqueue_active (&cl->tx_wait))
@@ -1368,11 +1368,10 @@ void mei_timer(struct work_struct *work) dev->iamthif_state =MEI_IAMTHIF_IDLE ; dev->iamthif_timer =0 ; -if (dev->iamthif_current_cb) -mei_free_cb_private (dev->iamthif_current_cb); +mei_io_cb_free (dev->iamthif_current_cb); + dev->iamthif_current_cb =NULL ; dev->iamthif_file_object =NULL ; - dev->iamthif_current_cb =NULL ;mei_run_next_iamthif_cmd (dev); } }
@@ -1404,12 +1403,11 @@ void mei_timer(struct work_struct *work)if (cl_pos == &dev->iamthif_cl)list_del (&cb_pos->list); } -if (dev->iamthif_current_cb) -mei_free_cb_private (dev->iamthif_current_cb); +mei_io_cb_free (dev->iamthif_current_cb); + dev->iamthif_current_cb =NULL ; dev->iamthif_file_object->private_data =NULL ; dev->iamthif_file_object =NULL ; - dev->iamthif_current_cb =NULL ; dev->iamthif_timer =0 ;mei_run_next_iamthif_cmd (dev);
drivers/misc/mei/iorw.c +18 -17
@@ -39,6 +39,21 @@#include "interface.h" /** +* mei_io_cb_free - free mei_cb_private related memory +* +* @cb: mei callback struct +*/ +void mei_io_cb_free (struct mei_cl_cb *cb) +{ +if (cb ==NULL ) +return ; + +kfree (cb->request_buffer.data); +kfree (cb->response_buffer.data); +kfree (cb); +} + +/** * mei_me_cl_by_id return index to me_clients for client_id * * @dev: the device structure
@@ -231,7 +246,7 @@ int mei_ioctl_connect_client(struct file *file, rets =0 ; end:dev_dbg (&dev->pdev->dev,"free connect cb memory." ); -kfree (cb); +mei_io_cb_free (cb);return rets; }
@@ -375,7 +390,7 @@ int amthi_read(struct mei_device *dev, struct file *file, free:dev_dbg (&dev->pdev->dev,"free amthi cb memory.\n" ); *offset =0 ; -mei_free_cb_private (cb); +mei_io_cb_free (cb); out:return rets; }
@@ -444,7 +459,7 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl) }return rets; unlock: -mei_free_cb_private (cb); +mei_io_cb_free (cb);return rets; }
@@ -568,17 +583,3 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev) } } -/** -* mei_free_cb_private - free mei_cb_private related memory -* -* @cb: mei callback struct -*/ -void mei_free_cb_private (struct mei_cl_cb *cb) -{ -if (cb ==NULL ) -return ; - -kfree (cb->request_buffer.data); -kfree (cb->response_buffer.data); -kfree (cb); -}
drivers/misc/mei/main.c +7 -7
@@ -124,7 +124,7 @@ static bool mei_clear_list(struct mei_device *dev,mei_send_flow_control (dev, &dev->iamthif_cl); }/* free all allocated buffers */ -mei_free_cb_private (cb_pos); +mei_io_cb_free (cb_pos); cb_pos =NULL ; removed = true; }
@@ -169,7 +169,7 @@ static bool mei_clear_lists(struct mei_device *dev, struct file *file)/* check file and iamthif current cb association */ if (dev->iamthif_current_cb->file_object == file) {/* remove cb */ -mei_free_cb_private (dev->iamthif_current_cb); +mei_io_cb_free (dev->iamthif_current_cb); dev->iamthif_current_cb =NULL ; removed = true; }
@@ -332,7 +332,7 @@ static int mei_release(struct inode *inode, struct file *file) file->private_data =NULL ;if (cb) { -mei_free_cb_private (cb); +mei_io_cb_free (cb); cb =NULL ; }
@@ -504,7 +504,7 @@ free:/* Remove entry from read list */ if (cb_pos)list_del (&cb_pos->list); -mei_free_cb_private (cb); +mei_io_cb_free (cb); cl->reading_state =MEI_IDLE ; cl->read_cb =NULL ; cl->read_pending =0 ;
@@ -651,7 +651,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, cl->reading_state == MEI_READ_COMPLETE) { *offset =0 ;list_del (&write_cb->list); -mei_free_cb_private (write_cb); +mei_io_cb_free (write_cb); write_cb =NULL ; } }
@@ -663,7 +663,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, write_cb =find_read_list_entry (dev, cl);if (write_cb) {list_del (&write_cb->list); -mei_free_cb_private (write_cb); +mei_io_cb_free (write_cb); write_cb =NULL ; cl->reading_state =MEI_IDLE ; cl->read_cb =NULL ;
@@ -778,7 +778,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, unlock_dev:mutex_unlock (&dev->device_lock); -mei_free_cb_private (write_cb); +mei_io_cb_free (write_cb);return rets; }
drivers/misc/mei/mei_dev.h +3 -2
@@ -291,8 +291,10 @@ int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);int mei_me_cl_by_id (struct mei_device *dev,u8 client_id);/* -* MEI IO List Functions +* MEI IO Functions */ +void mei_io_cb_free (struct mei_cl_cb *priv_cb); +/** * mei_io_list_init - Sets up a queue list. *
@@ -361,7 +363,6 @@ struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,void mei_run_next_iamthif_cmd (struct mei_device *dev); -void mei_free_cb_private (struct mei_cl_cb *priv_cb);/*
Signature · 1 line
1.7.4.4
PATCH 2/6 mei: add allocation and initialization wrappers for io callback
In reply to Tomas Winklermei_io_cb_init - allocat and initializate mei_cl_cb mei_io_cb_alloc_req/resp_buf are separate function as buffers are not always needed
--- drivers/misc/mei/main.c | 111 ++++++++++++++++++++++++++++++++++++---------- 1 files changed, 87 insertions(+), 24 deletions(-)
drivers/misc/mei/main.c +87 -24
@@ -516,6 +516,83 @@ out: }/** +* mei_io_cb_init - allocate and initialize io callback +* +* @cl - mei client +* @file: pointer to file structure +* +* returns mei_cl_cb pointer or NULL; +*/ +static struct mei_cl_cb *mei_io_cb_init (struct mei_cl *cl,struct file *fp) +{ +struct mei_cl_cb *cb; +struct mei_device *dev; + + dev = cl->dev; + + cb =kzalloc (sizeof (struct mei_cl_cb ),GFP_KERNEL ); +if (!cb) +return NULL ; + +INIT_LIST_HEAD (&cb->cb_list); + + cb->file_object = fp; + cb->file_private = cl; + cb->buf_idx =0 ; +return cb; +} + + +/** +* mei_io_cb_alloc_req_buf - allocate request buffer +* +* @cb - io callback structure +* @size: size of the buffer +* +* returns 0 on success +* -EINVAL if cb is NULL +* -ENOMEM if allocation failed +*/ +static int mei_io_cb_alloc_req_buf (struct mei_cl_cb *cb,size_t length) +{ +if (!cb) +return -EINVAL ; + +if (length ==0 ) +return 0 ; + + cb->request_buffer.data =kmalloc (length,GFP_KERNEL ); +if (!cb->request_buffer.data) +return -ENOMEM ; + cb->request_buffer.size = length; +return 0 ; +} +/** +* mei_io_cb_alloc_req_buf - allocate respose buffer +* +* @cb - io callback structure +* @size: size of the buffer +* +* returns 0 on success +* -EINVAL if cb is NULL +* -ENOMEM if allocation failed +*/ +static int mei_io_cb_alloc_resp_buf (struct mei_cl_cb *cb,size_t length) +{ +if (!cb) +return -EINVAL ; + +if (length ==0 ) +return 0 ; + + cb->response_buffer.data =kmalloc (length,GFP_KERNEL ); +if (!cb->response_buffer.data) +return -ENOMEM ; + cb->response_buffer.size = length; +return 0 ; +} + +/** * mei_write - the write function. * * @file: pointer to file structure
@@ -581,20 +658,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, *offset =0 ; - write_cb =kzalloc (sizeof (struct mei_cl_cb ),GFP_KERNEL ); + write_cb =mei_io_cb_init (cl, file);if (!write_cb) { -mutex_unlock (&dev->device_lock); -return -ENOMEM ; +dev_err (&dev->pdev->dev,"write cb allocation failed\n" ); + rets = -ENOMEM ; + goto unlock_dev; } - - write_cb->file_object = file; - write_cb->file_private = cl; - write_cb->request_buffer.data =kmalloc (length,GFP_KERNEL ); - rets = -ENOMEM ; -if (!write_cb->request_buffer.data) + rets =mei_io_cb_alloc_req_buf (write_cb, length); +if (rets) goto unlock_dev; -dev_dbg (&dev->pdev->dev,"length =%d\n" , (int ) length); +dev_dbg (&dev->pdev->dev,"cb request size = %zd\n" , length); rets = -EFAULT ;if (copy_from_user (write_cb->request_buffer.data, ubuf, length))
@@ -610,14 +684,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, write_cb->request_buffer.data, 4) == 0))) cl->sm_state |=MEI_WD_STATE_INDEPENDENCE_MSG_SENT ; -INIT_LIST_HEAD (&write_cb->cb_list);if (cl == &dev->iamthif_cl) { - write_cb->response_buffer.data = -kmalloc (dev->iamthif_mtu,GFP_KERNEL ); -if (!write_cb->response_buffer.data) { - rets = -ENOMEM ; - goto unlock_dev; - }if (dev->dev_state !=MEI_DEV_ENABLED ) { rets = -ENODEV ; goto unlock_dev;
@@ -632,11 +699,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, rets = -EMSGSIZE ; goto unlock_dev; } + rets =mei_io_cb_alloc_resp_buf (write_cb, dev->iamthif_mtu); +if (rets) + goto unlock_dev; - write_cb->response_buffer.size = dev->iamthif_mtu; write_cb->major_file_operations =MEI_IOCTL ; - write_cb->buf_idx =0 ; - write_cb->request_buffer.size = length;if (dev->iamthif_cl.state !=MEI_FILE_CONNECTED ) { rets = -ENODEV ; goto unlock_dev;
@@ -666,9 +733,6 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, } write_cb->major_file_operations =MEI_WRITE ; -/* make sure buffer index is zero before we start */ - write_cb->buf_idx =0 ; - write_cb->request_buffer.size = length;dev_dbg (&dev->pdev->dev,"host client = %d, ME client = %d\n" , cl->host_client_id, cl->me_client_id);
@@ -688,7 +752,6 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, rets = -EINVAL ; goto unlock_dev; } - write_cb->file_private = cl; rets =mei_flow_ctrl_creds (dev, cl);if (rets <0 )
Signature · 1 line
1.7.4.4