diff options
-rw-r--r-- | drivers/char/virtio_console.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 8722656cdebf..8a15af3e1a9d 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -936,16 +936,21 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe, | |||
936 | * pipe->nrbufs == 0 means there are no data to transfer, | 936 | * pipe->nrbufs == 0 means there are no data to transfer, |
937 | * so this returns just 0 for no data. | 937 | * so this returns just 0 for no data. |
938 | */ | 938 | */ |
939 | if (!pipe->nrbufs) | 939 | pipe_lock(pipe); |
940 | return 0; | 940 | if (!pipe->nrbufs) { |
941 | ret = 0; | ||
942 | goto error_out; | ||
943 | } | ||
941 | 944 | ||
942 | ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); | 945 | ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); |
943 | if (ret < 0) | 946 | if (ret < 0) |
944 | return ret; | 947 | goto error_out; |
945 | 948 | ||
946 | buf = alloc_buf(port->out_vq, 0, pipe->nrbufs); | 949 | buf = alloc_buf(port->out_vq, 0, pipe->nrbufs); |
947 | if (!buf) | 950 | if (!buf) { |
948 | return -ENOMEM; | 951 | ret = -ENOMEM; |
952 | goto error_out; | ||
953 | } | ||
949 | 954 | ||
950 | sgl.n = 0; | 955 | sgl.n = 0; |
951 | sgl.len = 0; | 956 | sgl.len = 0; |
@@ -953,12 +958,17 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe, | |||
953 | sgl.sg = buf->sg; | 958 | sgl.sg = buf->sg; |
954 | sg_init_table(sgl.sg, sgl.size); | 959 | sg_init_table(sgl.sg, sgl.size); |
955 | ret = __splice_from_pipe(pipe, &sd, pipe_to_sg); | 960 | ret = __splice_from_pipe(pipe, &sd, pipe_to_sg); |
961 | pipe_unlock(pipe); | ||
956 | if (likely(ret > 0)) | 962 | if (likely(ret > 0)) |
957 | ret = __send_to_port(port, buf->sg, sgl.n, sgl.len, buf, true); | 963 | ret = __send_to_port(port, buf->sg, sgl.n, sgl.len, buf, true); |
958 | 964 | ||
959 | if (unlikely(ret <= 0)) | 965 | if (unlikely(ret <= 0)) |
960 | free_buf(buf, true); | 966 | free_buf(buf, true); |
961 | return ret; | 967 | return ret; |
968 | |||
969 | error_out: | ||
970 | pipe_unlock(pipe); | ||
971 | return ret; | ||
962 | } | 972 | } |
963 | 973 | ||
964 | static unsigned int port_fops_poll(struct file *filp, poll_table *wait) | 974 | static unsigned int port_fops_poll(struct file *filp, poll_table *wait) |