* [PATCH] virtio_console: fix sparse warnings
@ 2014-12-01 11:35 Michael S. Tsirkin
2015-02-03 23:48 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2014-12-01 11:35 UTC (permalink / raw)
To: linux-kernel; +Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, virtualization
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: Michael S. Tsirkin <mst@redhat.com>
---
drivers/char/virtio_console.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 775c898..ccb5357 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -669,8 +669,8 @@ done:
* Give out the data that's requested from the buffer that we have
* queued up.
*/
-static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
- bool to_user)
+static ssize_t fill_readbuf(struct port *port, char __user *out_buf,
+ size_t out_count, bool to_user)
{
struct port_buffer *buf;
unsigned long flags;
@@ -688,7 +688,8 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
if (ret)
return -EFAULT;
} 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;
@@ -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. */
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)
--
MST
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio_console: fix sparse warnings
2014-12-01 11:35 [PATCH] virtio_console: fix sparse warnings Michael S. Tsirkin
@ 2015-02-03 23:48 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2015-02-03 23:48 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: linux-kernel, Amit Shah, Arnd Bergmann, virtualization
On Mon, Dec 01, 2014 at 01:35:57PM +0200, Michael S. Tsirkin wrote:
> 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.
That's horrid, don't do that. Have two different functions for this
type of thing, otherwise you defeat the whole purpose of trying to track
__user pointers.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-03 23:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-01 11:35 [PATCH] virtio_console: fix sparse warnings Michael S. Tsirkin
2015-02-03 23:48 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox