Merge tag 'armsoc-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[cascardo/linux.git] / drivers / misc / mei / interrupt.c
index 466c1d2..3f84d2e 100644 (file)
@@ -68,18 +68,6 @@ static inline int mei_cl_hbm_equal(struct mei_cl *cl,
        return cl->host_client_id == mei_hdr->host_addr &&
                cl->me_client_id == mei_hdr->me_addr;
 }
-/**
- * mei_cl_is_reading - checks if the client is in reading state
- *
- * @cl: mei client
- *
- * Return: true if the client is reading
- */
-static bool mei_cl_is_reading(struct mei_cl *cl)
-{
-       return cl->state == MEI_FILE_CONNECTED &&
-               cl->reading_state != MEI_READ_COMPLETE;
-}
 
 /**
  * mei_irq_discard_msg  - discard received message
@@ -116,37 +104,29 @@ int mei_cl_irq_read_msg(struct mei_cl *cl,
        struct mei_cl_cb *cb;
        unsigned char *buffer = NULL;
 
-       list_for_each_entry(cb, &dev->read_list.list, list) {
-               if (cl == cb->cl)
-                       break;
-       }
-
-       if (&cb->list == &dev->read_list.list) {
-               dev_err(dev->dev, "no reader found\n");
+       cb = list_first_entry_or_null(&cl->rd_pending, struct mei_cl_cb, list);
+       if (!cb) {
+               cl_err(dev, cl, "pending read cb not found\n");
                goto out;
        }
 
-       if (!mei_cl_is_reading(cl)) {
-               cl_err(dev, cl, "cl is not reading state=%d reading state=%d\n",
-                       cl->state, cl->reading_state);
+       if (!mei_cl_is_connected(cl)) {
+               cl_dbg(dev, cl, "not connected\n");
+               cb->status = -ENODEV;
                goto out;
        }
 
-       cl->reading_state = MEI_READING;
-
-       if (cb->response_buffer.size == 0 ||
-           cb->response_buffer.data == NULL) {
+       if (cb->buf.size == 0 || cb->buf.data == NULL) {
                cl_err(dev, cl, "response buffer is not allocated.\n");
                list_move_tail(&cb->list, &complete_list->list);
                cb->status = -ENOMEM;
                goto out;
        }
 
-       if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) {
+       if (cb->buf.size < mei_hdr->length + cb->buf_idx) {
                cl_dbg(dev, cl, "message overflow. size %d len %d idx %ld\n",
-                       cb->response_buffer.size, mei_hdr->length, cb->buf_idx);
-               buffer = krealloc(cb->response_buffer.data,
-                                 mei_hdr->length + cb->buf_idx,
+                       cb->buf.size, mei_hdr->length, cb->buf_idx);
+               buffer = krealloc(cb->buf.data, mei_hdr->length + cb->buf_idx,
                                  GFP_KERNEL);
 
                if (!buffer) {
@@ -154,19 +134,18 @@ int mei_cl_irq_read_msg(struct mei_cl *cl,
                        list_move_tail(&cb->list, &complete_list->list);
                        goto out;
                }
-               cb->response_buffer.data = buffer;
-               cb->response_buffer.size = mei_hdr->length + cb->buf_idx;
+               cb->buf.data = buffer;
+               cb->buf.size = mei_hdr->length + cb->buf_idx;
        }
 
-       buffer = cb->response_buffer.data + cb->buf_idx;
+       buffer = cb->buf.data + cb->buf_idx;
        mei_read_slots(dev, buffer, mei_hdr->length);
 
        cb->buf_idx += mei_hdr->length;
 
        if (mei_hdr->msg_complete) {
                cb->read_time = jiffies;
-               cl_dbg(dev, cl, "completed read length = %lu\n",
-                       cb->buf_idx);
+               cl_dbg(dev, cl, "completed read length = %lu\n", cb->buf_idx);
                list_move_tail(&cb->list, &complete_list->list);
        }
 
@@ -204,7 +183,6 @@ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,
 
        cl->state = MEI_FILE_DISCONNECTED;
        cl->status = 0;
-       list_del(&cb->list);
        mei_io_cb_free(cb);
 
        return ret;
@@ -284,7 +262,7 @@ static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb,
                return ret;
        }
 
-       list_move_tail(&cb->list, &dev->read_list.list);
+       list_move_tail(&cb->list, &cl->rd_pending);
 
        return 0;
 }
@@ -322,7 +300,7 @@ static int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb,
        if (ret) {
                cl->status = ret;
                cb->buf_idx = 0;
-               list_del(&cb->list);
+               list_del_init(&cb->list);
                return ret;
        }