Commit 48b36066 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin

virtio_console: fix sparse warnings

CHECK drivers/char/virtio_console.c
drivers/char/virtio_console.c:687:36: warning: incorrect type in
	argument 1 (different address spaces)
drivers/char/virtio_console.c:687:36:    expected void [noderef]
	<asn:1>*to
drivers/char/virtio_console.c:687:36:    got char *out_buf
drivers/char/virtio_console.c:790:35: warning: incorrect type in
	argument 2 (different address spaces)
drivers/char/virtio_console.c:790:35:    expected char *out_buf
drivers/char/virtio_console.c:790:35:    got char [noderef]
	<asn:1>*ubuf

fill_readbuf is reused with both kernel and userspace pointers,
depending on value of to_user flag.

Tag address parameter as __user, and cast to/from regular pointer type
when we know it's safe.
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>


parent 2e73c716
...@@ -669,8 +669,8 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg, ...@@ -669,8 +669,8 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,
* Give out the data that's requested from the buffer that we have * Give out the data that's requested from the buffer that we have
* queued up. * queued up.
*/ */
static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count, static ssize_t fill_readbuf(struct port *port, char __user *out_buf,
bool to_user) size_t out_count, bool to_user)
{ {
struct port_buffer *buf; struct port_buffer *buf;
unsigned long flags; unsigned long flags;
...@@ -688,7 +688,8 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count, ...@@ -688,7 +688,8 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
if (ret) if (ret)
return -EFAULT; return -EFAULT;
} else { } else {
memcpy(out_buf, buf->buf + buf->offset, out_count); memcpy((__force char *)out_buf, buf->buf + buf->offset,
out_count);
} }
buf->offset += out_count; buf->offset += out_count;
...@@ -1162,7 +1163,7 @@ static int get_chars(u32 vtermno, char *buf, int count) ...@@ -1162,7 +1163,7 @@ static int get_chars(u32 vtermno, char *buf, int count)
/* If we don't have an input queue yet, we can't get input. */ /* If we don't have an input queue yet, we can't get input. */
BUG_ON(!port->in_vq); BUG_ON(!port->in_vq);
return fill_readbuf(port, buf, count, false); return fill_readbuf(port, (__force char __user *)buf, count, false);
} }
static void resize_console(struct port *port) static void resize_console(struct port *port)
......
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