diff options
author | Amit Shah <amit.shah@redhat.com> | 2011-09-14 03:36:43 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-11-01 21:11:00 -0400 |
commit | d25a9ddae93ca97aa03fdab1363baf0e0c35d960 (patch) | |
tree | fea9bd4041716248fdfd8db78bab715f1d907670 /drivers/char/virtio_console.c | |
parent | defde66996476295dc7b1b60ea318965f8c3ad86 (diff) |
virtio: console: make get_inbuf() return port->inbuf if present
Instead of pulling in a buffer from the vq each time it's called,
get_inbuf() now checks if the current active buffer, in port->inbuf is
valid. If it is, just returns a pointer to it. This ends up
simplifying a lot of code calling get_inbuf() since the check for
port->inbuf being valid was done by all the callers.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/char/virtio_console.c')
-rw-r--r-- | drivers/char/virtio_console.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 3516aeb7f06c..cb5edf33bebf 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -351,11 +351,12 @@ fail: | |||
351 | static struct port_buffer *get_inbuf(struct port *port) | 351 | static struct port_buffer *get_inbuf(struct port *port) |
352 | { | 352 | { |
353 | struct port_buffer *buf; | 353 | struct port_buffer *buf; |
354 | struct virtqueue *vq; | ||
355 | unsigned int len; | 354 | unsigned int len; |
356 | 355 | ||
357 | vq = port->in_vq; | 356 | if (port->inbuf) |
358 | buf = virtqueue_get_buf(vq, &len); | 357 | return port->inbuf; |
358 | |||
359 | buf = virtqueue_get_buf(port->in_vq, &len); | ||
359 | if (buf) { | 360 | if (buf) { |
360 | buf->len = len; | 361 | buf->len = len; |
361 | buf->offset = 0; | 362 | buf->offset = 0; |
@@ -418,18 +419,12 @@ static bool port_has_data(struct port *port) | |||
418 | unsigned long flags; | 419 | unsigned long flags; |
419 | bool ret; | 420 | bool ret; |
420 | 421 | ||
422 | ret = false; | ||
421 | spin_lock_irqsave(&port->inbuf_lock, flags); | 423 | spin_lock_irqsave(&port->inbuf_lock, flags); |
422 | if (port->inbuf) { | ||
423 | ret = true; | ||
424 | goto out; | ||
425 | } | ||
426 | port->inbuf = get_inbuf(port); | 424 | port->inbuf = get_inbuf(port); |
427 | if (port->inbuf) { | 425 | if (port->inbuf) |
428 | ret = true; | 426 | ret = true; |
429 | goto out; | 427 | |
430 | } | ||
431 | ret = false; | ||
432 | out: | ||
433 | spin_unlock_irqrestore(&port->inbuf_lock, flags); | 428 | spin_unlock_irqrestore(&port->inbuf_lock, flags); |
434 | return ret; | 429 | return ret; |
435 | } | 430 | } |
@@ -1489,8 +1484,7 @@ static void in_intr(struct virtqueue *vq) | |||
1489 | return; | 1484 | return; |
1490 | 1485 | ||
1491 | spin_lock_irqsave(&port->inbuf_lock, flags); | 1486 | spin_lock_irqsave(&port->inbuf_lock, flags); |
1492 | if (!port->inbuf) | 1487 | port->inbuf = get_inbuf(port); |
1493 | port->inbuf = get_inbuf(port); | ||
1494 | 1488 | ||
1495 | /* | 1489 | /* |
1496 | * Don't queue up data when port is closed. This condition | 1490 | * Don't queue up data when port is closed. This condition |