[char-misc-next 9/9] mei: revamp io list cleanup function.

From: Tomas Winkler
Date: Fri Jan 27 2017 - 08:41:38 EST


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: Tomas Winkler <tomas.winkler@xxxxxxxxx>
---
drivers/misc/mei/amthif.c | 34 ++++---------------
drivers/misc/mei/client.c | 83 ++++++++++++++++++++++-------------------------
drivers/misc/mei/client.h | 2 +-
3 files changed, 47 insertions(+), 72 deletions(-)

diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index 366ef1fe9b90..0e7406ccb6dd 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -311,50 +311,30 @@ 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;
}
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 838a4a349f9e..68fe37b5bc52 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -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);
}

/**
@@ -504,27 +521,6 @@ struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp)
}

/**
- * 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.
*
* @cl: host client
@@ -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
*/
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index f48cfa026268..545ae319ba90 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -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);
--
2.7.4