From: Eric Biggers <ebiggers@xxxxxxxxxx> Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx> --- fs/fsopen.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fs/fsopen.c b/fs/fsopen.c index 1fbd8b0ca194b..dd38f6b65aace 100644 --- a/fs/fsopen.c +++ b/fs/fsopen.c @@ -161,20 +161,18 @@ static ssize_t fscontext_read(struct file *file, if (ret < 0) return ret; - ret = -ENODATA; - if (log->head != log->tail) { - index = log->tail & (logsize - 1); - p = log->buffer[index]; - need_free = log->need_free & (1 << index); - log->buffer[index] = NULL; - log->need_free &= ~(1 << index); - log->tail++; - ret = 0; + if (log->head == log->tail) { + mutex_unlock(&fc->uapi_mutex); + return -ENODATA; } + index = log->tail & (logsize - 1); + p = log->buffer[index]; + need_free = log->need_free & (1 << index); + log->buffer[index] = NULL; + log->need_free &= ~(1 << index); + log->tail++; mutex_unlock(&fc->uapi_mutex); - if (ret < 0) - return ret; ret = -EMSGSIZE; n = strlen(p); -- 2.18.0