@@ -349,6 +349,36 @@ void mei_io_cb_free(struct mei_cl_cb *cb)
349349 kfree (cb );
350350}
351351
352+ /**
353+ * mei_tx_cb_queue - queue tx callback
354+ *
355+ * Locking: called under "dev->device_lock" lock
356+ *
357+ * @cb: mei callback struct
358+ * @head: an instance of list to queue on
359+ */
360+ static inline void mei_tx_cb_enqueue (struct mei_cl_cb * cb ,
361+ struct list_head * head )
362+ {
363+ list_add_tail (& cb -> list , head );
364+ cb -> cl -> tx_cb_queued ++ ;
365+ }
366+
367+ /**
368+ * mei_tx_cb_dequeue - dequeue tx callback
369+ *
370+ * Locking: called under "dev->device_lock" lock
371+ *
372+ * @cb: mei callback struct to dequeue and free
373+ */
374+ static inline void mei_tx_cb_dequeue (struct mei_cl_cb * cb )
375+ {
376+ if (!WARN_ON (cb -> cl -> tx_cb_queued == 0 ))
377+ cb -> cl -> tx_cb_queued -- ;
378+
379+ mei_io_cb_free (cb );
380+ }
381+
352382/**
353383 * mei_io_cb_init - allocate and initialize io callback
354384 *
@@ -377,49 +407,37 @@ static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl,
377407}
378408
379409/**
380- * __mei_io_list_flush_cl - removes and frees cbs belonging to cl.
410+ * mei_io_list_flush_cl - removes cbs belonging to the cl.
381411 *
382412 * @head: an instance of our list structure
383- * @cl: host client, can be NULL for flushing the whole list
384- * @free: whether to free the cbs
413+ * @cl: host client
385414 */
386- static void __mei_io_list_flush_cl (struct list_head * head ,
387- const struct mei_cl * cl , bool free )
415+ static void mei_io_list_flush_cl (struct list_head * head ,
416+ const struct mei_cl * cl )
388417{
389418 struct mei_cl_cb * cb , * next ;
390419
391- /* enable removing everything if no cl is specified */
392420 list_for_each_entry_safe (cb , next , head , list ) {
393- if (! cl || mei_cl_cmp_id (cl , cb -> cl )) {
421+ if (mei_cl_cmp_id (cl , cb -> cl ))
394422 list_del_init (& cb -> list );
395- if (free )
396- mei_io_cb_free (cb );
397- }
398423 }
399424}
400425
401426/**
402- * mei_io_list_flush_cl - removes list entry belonging to cl.
427+ * mei_io_tx_list_free_cl - removes cb belonging to the cl and free them
403428 *
404429 * @head: An instance of our list structure
405430 * @cl: host client
406431 */
407- static inline void mei_io_list_flush_cl (struct list_head * head ,
408- const struct mei_cl * cl )
432+ static void mei_io_tx_list_free_cl (struct list_head * head ,
433+ const struct mei_cl * cl )
409434{
410- __mei_io_list_flush_cl (head , cl , false);
411- }
435+ struct mei_cl_cb * cb , * next ;
412436
413- /**
414- * mei_io_list_free_cl - removes cb belonging to cl and free them
415- *
416- * @head: An instance of our list structure
417- * @cl: host client
418- */
419- static inline void mei_io_list_free_cl (struct list_head * head ,
420- const struct mei_cl * cl )
421- {
422- __mei_io_list_flush_cl (head , cl , true);
437+ list_for_each_entry_safe (cb , next , head , list ) {
438+ if (mei_cl_cmp_id (cl , cb -> cl ))
439+ mei_tx_cb_dequeue (cb );
440+ }
423441}
424442
425443/**
@@ -538,8 +556,8 @@ int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp)
538556 dev = cl -> dev ;
539557
540558 cl_dbg (dev , cl , "remove list entry belonging to cl\n" );
541- mei_io_list_free_cl (& cl -> dev -> write_list , cl );
542- mei_io_list_free_cl (& cl -> dev -> write_waiting_list , cl );
559+ mei_io_tx_list_free_cl (& cl -> dev -> write_list , cl );
560+ mei_io_tx_list_free_cl (& cl -> dev -> write_waiting_list , cl );
543561 mei_io_list_flush_cl (& cl -> dev -> ctrl_wr_list , cl );
544562 mei_io_list_flush_cl (& cl -> dev -> ctrl_rd_list , cl );
545563 mei_io_list_free_fp (& cl -> rd_pending , fp );
@@ -756,8 +774,8 @@ static void mei_cl_set_disconnected(struct mei_cl *cl)
756774 return ;
757775
758776 cl -> state = MEI_FILE_DISCONNECTED ;
759- mei_io_list_free_cl (& dev -> write_list , cl );
760- mei_io_list_free_cl (& dev -> write_waiting_list , cl );
777+ mei_io_tx_list_free_cl (& dev -> write_list , cl );
778+ mei_io_tx_list_free_cl (& dev -> write_waiting_list , cl );
761779 mei_io_list_flush_cl (& dev -> ctrl_rd_list , cl );
762780 mei_io_list_flush_cl (& dev -> ctrl_wr_list , cl );
763781 mei_cl_wake_all (cl );
@@ -1693,9 +1711,9 @@ int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb)
16931711
16941712out :
16951713 if (mei_hdr .msg_complete )
1696- list_add_tail ( & cb -> list , & dev -> write_waiting_list );
1714+ mei_tx_cb_enqueue ( cb , & dev -> write_waiting_list );
16971715 else
1698- list_add_tail ( & cb -> list , & dev -> write_list );
1716+ mei_tx_cb_enqueue ( cb , & dev -> write_list );
16991717
17001718 cb = NULL ;
17011719 if (blocking && cl -> writing_state != MEI_WRITE_COMPLETE ) {
@@ -1741,7 +1759,7 @@ void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb)
17411759
17421760 switch (cb -> fop_type ) {
17431761 case MEI_FOP_WRITE :
1744- mei_io_cb_free (cb );
1762+ mei_tx_cb_dequeue (cb );
17451763 cl -> writing_state = MEI_WRITE_COMPLETE ;
17461764 if (waitqueue_active (& cl -> tx_wait )) {
17471765 wake_up_interruptible (& cl -> tx_wait );
0 commit comments