Commit f046192d authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

mei: revamp io list cleanup function.

Specify in function names by which object is the io list filtered:
cl for a client and fp for file descriptor.
In that course a code duplication is resolved by dropping
mei_cl_read_cb_flush and mei_clear_list and using
mei_io_list_free_fp function.
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 962ff7bc
......@@ -310,51 +310,31 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb)
}
}
/**
* mei_clear_list - removes all callbacks associated with file
* from mei_cb_list
*
* @file: file structure
* @mei_cb_list: callbacks list
*
* mei_clear_list is called to clear resources associated with file
* when application calls close function or Ctrl-C was pressed
*/
static void mei_clear_list(const struct file *file,
struct list_head *mei_cb_list)
{
struct mei_cl_cb *cb, *next;
list_for_each_entry_safe(cb, next, mei_cb_list, list)
if (file == cb->fp)
mei_io_cb_free(cb);
}
/**
* mei_amthif_release - the release function
*
* @dev: device structure
* @file: pointer to file structure
* @fp: pointer to file structure
*
* Return: 0 on success, <0 on error
*/
int mei_amthif_release(struct mei_device *dev, struct file *file)
int mei_amthif_release(struct mei_device *dev, struct file *fp)
{
struct mei_cl *cl = file->private_data;
struct mei_cl *cl = fp->private_data;
if (dev->iamthif_open_count > 0)
dev->iamthif_open_count--;
if (cl->fp == file && dev->iamthif_state != MEI_IAMTHIF_IDLE) {
if (cl->fp == fp && dev->iamthif_state != MEI_IAMTHIF_IDLE) {
dev_dbg(dev->dev, "amthif canceled iamthif state %d\n",
dev->iamthif_state);
dev->iamthif_state);
dev->iamthif_canceled = true;
}
/* Don't clean ctrl_rd_list here, the reads has to be completed */
mei_clear_list(file, &dev->amthif_cmd_list);
mei_clear_list(file, &cl->rd_completed);
mei_io_list_free_fp(&dev->amthif_cmd_list, fp);
mei_io_list_free_fp(&cl->rd_completed, fp);
return 0;
}
......@@ -377,14 +377,14 @@ static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl,
}
/**
* __mei_io_list_flush - removes and frees cbs belonging to cl.
* __mei_io_list_flush_cl - removes and frees cbs belonging to cl.
*
* @head: an instance of our list structure
* @cl: host client, can be NULL for flushing the whole list
* @free: whether to free the cbs
*/
static void __mei_io_list_flush(struct list_head *head,
struct mei_cl *cl, bool free)
static void __mei_io_list_flush_cl(struct list_head *head,
const struct mei_cl *cl, bool free)
{
struct mei_cl_cb *cb, *next;
......@@ -399,25 +399,42 @@ static void __mei_io_list_flush(struct list_head *head,
}
/**
* mei_io_list_flush - removes list entry belonging to cl.
* mei_io_list_flush_cl - removes list entry belonging to cl.
*
* @head: An instance of our list structure
* @cl: host client
*/
static inline void mei_io_list_flush(struct list_head *head, struct mei_cl *cl)
static inline void mei_io_list_flush_cl(struct list_head *head,
const struct mei_cl *cl)
{
__mei_io_list_flush(head, cl, false);
__mei_io_list_flush_cl(head, cl, false);
}
/**
* mei_io_list_free - removes cb belonging to cl and free them
* mei_io_list_free_cl - removes cb belonging to cl and free them
*
* @head: An instance of our list structure
* @cl: host client
*/
static inline void mei_io_list_free(struct list_head *head, struct mei_cl *cl)
static inline void mei_io_list_free_cl(struct list_head *head,
const struct mei_cl *cl)
{
__mei_io_list_flush(head, cl, true);
__mei_io_list_flush_cl(head, cl, true);
}
/**
* mei_io_list_free_fp - free cb from a list that matches file pointer
*
* @head: io list
* @fp: file pointer (matching cb file object), may be NULL
*/
void mei_io_list_free_fp(struct list_head *head, const struct file *fp)
{
struct mei_cl_cb *cb, *next;
list_for_each_entry_safe(cb, next, head, list)
if (!fp || fp == cb->fp)
mei_io_cb_free(cb);
}
/**
......@@ -503,27 +520,6 @@ struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp)
return NULL;
}
/**
* mei_cl_read_cb_flush - free client's read pending and completed cbs
* for a specific file
*
* @cl: host client
* @fp: file pointer (matching cb file object), may be NULL
*/
void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp)
{
struct mei_cl_cb *cb, *next;
list_for_each_entry_safe(cb, next, &cl->rd_completed, list)
if (!fp || fp == cb->fp)
mei_io_cb_free(cb);
list_for_each_entry_safe(cb, next, &cl->rd_pending, list)
if (!fp || fp == cb->fp)
mei_io_cb_free(cb);
}
/**
* mei_cl_flush_queues - flushes queue lists belonging to cl.
*
......@@ -542,17 +538,16 @@ int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp)
dev = cl->dev;
cl_dbg(dev, cl, "remove list entry belonging to cl\n");
mei_io_list_free(&cl->dev->write_list, cl);
mei_io_list_free(&cl->dev->write_waiting_list, cl);
mei_io_list_flush(&cl->dev->ctrl_wr_list, cl);
mei_io_list_flush(&cl->dev->ctrl_rd_list, cl);
mei_cl_read_cb_flush(cl, fp);
mei_io_list_free_cl(&cl->dev->write_list, cl);
mei_io_list_free_cl(&cl->dev->write_waiting_list, cl);
mei_io_list_flush_cl(&cl->dev->ctrl_wr_list, cl);
mei_io_list_flush_cl(&cl->dev->ctrl_rd_list, cl);
mei_io_list_free_fp(&cl->rd_pending, fp);
mei_io_list_free_fp(&cl->rd_completed, fp);
return 0;
}
/**
* mei_cl_init - initializes cl.
*
......@@ -764,11 +759,11 @@ static void mei_cl_set_disconnected(struct mei_cl *cl)
return;
cl->state = MEI_FILE_DISCONNECTED;
mei_io_list_free(&dev->write_list, cl);
mei_io_list_free(&dev->write_waiting_list, cl);
mei_io_list_flush(&dev->ctrl_rd_list, cl);
mei_io_list_flush(&dev->ctrl_wr_list, cl);
mei_io_list_free(&dev->amthif_cmd_list, cl);
mei_io_list_free_cl(&dev->write_list, cl);
mei_io_list_free_cl(&dev->write_waiting_list, cl);
mei_io_list_flush_cl(&dev->ctrl_rd_list, cl);
mei_io_list_flush_cl(&dev->ctrl_wr_list, cl);
mei_io_list_free_cl(&dev->amthif_cmd_list, cl);
mei_cl_wake_all(cl);
cl->rx_flow_ctrl_creds = 0;
cl->tx_flow_ctrl_creds = 0;
......@@ -1123,8 +1118,8 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
if (!mei_cl_is_connected(cl)) {
if (cl->state == MEI_FILE_DISCONNECT_REQUIRED) {
mei_io_list_flush(&dev->ctrl_rd_list, cl);
mei_io_list_flush(&dev->ctrl_wr_list, cl);
mei_io_list_flush_cl(&dev->ctrl_rd_list, cl);
mei_io_list_flush_cl(&dev->ctrl_wr_list, cl);
/* ignore disconnect return valuue;
* in case of failure reset will be invoked
*/
......
......@@ -83,6 +83,7 @@ static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl)
* MEI IO Functions
*/
void mei_io_cb_free(struct mei_cl_cb *priv_cb);
void mei_io_list_free_fp(struct list_head *head, const struct file *fp);
/*
* MEI Host Client Functions
......@@ -99,7 +100,6 @@ struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev);
struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl,
const struct file *fp);
void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp);
struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length,
enum mei_cb_file_ops type,
const struct file *fp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment