Commit 8b2458f4 authored by Alexander Usyskin's avatar Alexander Usyskin Committed by Greg Kroah-Hartman

mei: always copy the read buffer if data is ready

Copy completed callback content to the user space
if we have such callback ready in the beginning of the read.
Simplify offset processing logic as byproduct.

This is a refinement for:
commit 139aacf7 ("mei: fix read after read scenario")
Signed-off-by: default avatarAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 13cf9885
...@@ -159,27 +159,22 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, ...@@ -159,27 +159,22 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
goto out; goto out;
} }
if (ubuf == NULL) {
rets = -EMSGSIZE;
goto out;
}
if (cl == &dev->iamthif_cl) { if (cl == &dev->iamthif_cl) {
rets = mei_amthif_read(dev, file, ubuf, length, offset); rets = mei_amthif_read(dev, file, ubuf, length, offset);
goto out; goto out;
} }
cb = mei_cl_read_cb(cl, file); cb = mei_cl_read_cb(cl, file);
if (cb) { if (cb)
/* read what left */
if (cb->buf_idx > *offset)
goto copy_buffer; goto copy_buffer;
/* offset is beyond buf_idx we have no more data return 0 */
if (cb->buf_idx > 0 && cb->buf_idx <= *offset) { if (*offset > 0)
rets = 0;
goto free;
}
/* Offset needs to be cleaned for contiguous reads*/
if (cb->buf_idx == 0 && *offset > 0)
*offset = 0;
} else if (*offset > 0) {
*offset = 0; *offset = 0;
}
err = mei_cl_read_start(cl, length, file); err = mei_cl_read_start(cl, length, file);
if (err && err != -EBUSY) { if (err && err != -EBUSY) {
...@@ -231,10 +226,10 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, ...@@ -231,10 +226,10 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
goto free; goto free;
} }
cl_dbg(dev, cl, "buf.size = %d buf.idx = %ld\n", cl_dbg(dev, cl, "buf.size = %d buf.idx = %ld offset = %lld\n",
cb->buf.size, cb->buf_idx); cb->buf.size, cb->buf_idx, *offset);
if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) { if (*offset >= cb->buf_idx) {
rets = -EMSGSIZE; rets = 0;
goto free; goto free;
} }
...@@ -255,6 +250,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, ...@@ -255,6 +250,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
free: free:
mei_io_cb_free(cb); mei_io_cb_free(cb);
*offset = 0;
out: out:
cl_dbg(dev, cl, "end mei read rets = %d\n", rets); cl_dbg(dev, cl, "end mei read rets = %d\n", rets);
......
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