mei: fix memory leak of mei_clients array
[firefly-linux-kernel-4.4.55.git] / drivers / misc / mei / hbm.c
index b9a4bb5921f1b95ec231e2bc7aefb976bfbfcea4..804106209d764f9f248f6171df5d0dee8185567b 100644 (file)
@@ -59,6 +59,34 @@ static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status)
        }
 }
 
+/**
+ * mei_hbm_idle - set hbm to idle state
+ *
+ * @dev: the device structure
+ */
+void mei_hbm_idle(struct mei_device *dev)
+{
+       dev->init_clients_timer = 0;
+       dev->hbm_state = MEI_HBM_IDLE;
+}
+
+/**
+ * mei_hbm_reset - reset hbm counters and book keeping data structurs
+ *
+ * @dev: the device structure
+ */
+void mei_hbm_reset(struct mei_device *dev)
+{
+       dev->me_clients_num = 0;
+       dev->me_client_presentation_num = 0;
+       dev->me_client_index = 0;
+
+       kfree(dev->me_clients);
+       dev->me_clients = NULL;
+
+       mei_hbm_idle(dev);
+}
+
 /**
  * mei_hbm_me_cl_allocate - allocates storage for me clients
  *
@@ -71,9 +99,7 @@ static int mei_hbm_me_cl_allocate(struct mei_device *dev)
        struct mei_me_client *clients;
        int b;
 
-       dev->me_clients_num = 0;
-       dev->me_client_presentation_num = 0;
-       dev->me_client_index = 0;
+       mei_hbm_reset(dev);
 
        /* count how many ME clients we have */
        for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX)
@@ -82,9 +108,6 @@ static int mei_hbm_me_cl_allocate(struct mei_device *dev)
        if (dev->me_clients_num == 0)
                return 0;
 
-       kfree(dev->me_clients);
-       dev->me_clients = NULL;
-
        dev_dbg(&dev->pdev->dev, "memory allocation for ME clients size=%ld.\n",
                dev->me_clients_num * sizeof(struct mei_me_client));
        /* allocate storage for ME clients representation */
@@ -135,17 +158,6 @@ bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
 }
 
 
-/**
- * mei_hbm_idle - set hbm to idle state
- *
- * @dev: the device structure
- */
-void mei_hbm_idle(struct mei_device *dev)
-{
-       dev->init_clients_timer = 0;
-       dev->hbm_state = MEI_HBM_IDLE;
-}
-
 int mei_hbm_start_wait(struct mei_device *dev)
 {
        int ret;