From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>, Sasha Levin <levinsasha928@gmail.com>
Subject: [patch 2/3] kvm tool: serial: Simplify switch cases
Date: Sat, 10 Dec 2011 13:27:57 -0000 [thread overview]
Message-ID: <20111210132439.049356768@linutronix.de> (raw)
In-Reply-To: <20111210132220.083204833@linutronix.de>
[-- Attachment #1: kvm-tool-serial-simplify-switch-cases.patch --]
[-- Type: text/plain, Size: 3696 bytes --]
There is no point to have the same switch case construct for all the
registers, just to take care of the oddball case of DLL/DLM.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
tools/kvm/hw/serial.c | 129 +++++++++++++++++---------------------------------
1 file changed, 44 insertions(+), 85 deletions(-)
Index: linux-kvm/tools/kvm/hw/serial.c
===================================================================
--- linux-kvm.orig/tools/kvm/hw/serial.c
+++ linux-kvm/tools/kvm/hw/serial.c
@@ -187,73 +187,48 @@ static bool serial8250_out(struct ioport
offset = port - dev->iobase;
- if (dev->lcr & UART_LCR_DLAB) {
- switch (offset) {
- case UART_DLL:
- dev->dll = ioport__read8(data);
- break;
- case UART_DLM:
- dev->dlm = ioport__read8(data);
- break;
- case UART_FCR:
- dev->fcr = ioport__read8(data);
- break;
- case UART_LCR:
- dev->lcr = ioport__read8(data);
- break;
- case UART_MCR:
- dev->mcr = ioport__read8(data);
- break;
- case UART_LSR:
- /* Factory test */
- break;
- case UART_MSR:
- /* Not used */
- break;
- case UART_SCR:
- dev->scr = ioport__read8(data);
- break;
- default:
- ret = false;
- break;
- }
- } else {
- switch (offset) {
- case UART_TX: {
+ switch (offset) {
+ case UART_TX:
+ if (!(dev->lcr & UART_LCR_DLAB)) {
char *addr = data;
if (!(dev->mcr & UART_MCR_LOOP))
term_putc(CONSOLE_8250, addr, size, dev->id);
dev->iir = UART_IIR_NO_INT;
- break;
+ } else {
+ dev->dll = ioport__read8(data);
}
- case UART_FCR:
- dev->fcr = ioport__read8(data);
- break;
- case UART_IER:
+ break;
+ case UART_IER:
+ if (!(dev->lcr & UART_LCR_DLAB)) {
dev->ier = ioport__read8(data) & 0x3f;
kvm__irq_line(kvm, dev->irq, dev->ier ? 1 : 0);
- break;
- case UART_LCR:
- dev->lcr = ioport__read8(data);
- break;
- case UART_MCR:
- dev->mcr = ioport__read8(data);
- break;
- case UART_LSR:
- /* Factory test */
- break;
- case UART_MSR:
- /* Not used */
- break;
- case UART_SCR:
- dev->scr = ioport__read8(data);
- break;
- default:
- ret = false;
- break;
+ } else {
+ dev->dlm = ioport__read8(data);
}
+ break;
+ case UART_FCR:
+ dev->fcr = ioport__read8(data);
+ break;
+ case UART_LCR:
+ dev->lcr = ioport__read8(data);
+ break;
+ case UART_MCR:
+ dev->mcr = ioport__read8(data);
+ break;
+ case UART_LSR:
+ /* Factory test */
+ break;
+ case UART_MSR:
+ /* Not used */
+ break;
+ case UART_SCR:
+ dev->scr = ioport__read8(data);
+ break;
+ default:
+ ret = false;
+ break;
}
mutex_unlock(&dev->mutex);
@@ -275,37 +250,22 @@ static bool serial8250_in(struct ioport
offset = port - dev->iobase;
- if (dev->lcr & UART_LCR_DLAB) {
- switch (offset) {
- case UART_DLL:
+ switch (offset) {
+ case UART_RX:
+ if (dev->lcr & UART_LCR_DLAB) {
ioport__write8(data, dev->dll);
- goto out_unlock;
-
- case UART_DLM:
- ioport__write8(data, dev->dlm);
- goto out_unlock;
-
- default:
- break;
- }
- } else {
- switch (offset) {
- case UART_RX:
+ } else {
ioport__write8(data, dev->rbr);
dev->lsr &= ~UART_LSR_DR;
dev->iir = UART_IIR_NO_INT;
- goto out_unlock;
-
- case UART_IER:
- ioport__write8(data, dev->ier);
- goto out_unlock;
-
- default:
- break;
}
- }
-
- switch (offset) {
+ break;
+ case UART_IER:
+ if (dev->lcr & UART_LCR_DLAB)
+ ioport__write8(data, dev->dlm);
+ else
+ ioport__write8(data, dev->ier);
+ break;
case UART_IIR: {
u8 iir = dev->iir;
@@ -333,9 +293,8 @@ static bool serial8250_in(struct ioport
break;
default:
ret = false;
- goto out_unlock;
+ break;
}
-out_unlock:
mutex_unlock(&dev->mutex);
return ret;
next prev parent reply other threads:[~2011-12-10 13:28 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-10 13:27 [patch 0/3] kvm tool: Serial emulation overhaul Thomas Gleixner
2011-12-10 13:27 ` [patch 1/3] kvm tool: serial: Cleanup coding style Thomas Gleixner
2011-12-10 13:27 ` [patch 3/3] kvm tool: serial: Fix interrupt handling Thomas Gleixner
2011-12-10 13:27 ` Thomas Gleixner [this message]
2011-12-10 15:17 ` [patch 0/3] kvm tool: Serial emulation overhaul Pekka Enberg
2011-12-10 20:51 ` Thomas Gleixner
2011-12-11 8:15 ` Pekka Enberg
2011-12-11 10:30 ` Ingo Molnar
2011-12-11 10:46 ` Ingo Molnar
2011-12-11 14:04 ` Thomas Gleixner
2011-12-11 15:53 ` Ingo Molnar
2011-12-12 5:30 ` Sasha Levin
2011-12-12 11:12 ` Ingo Molnar
2011-12-12 11:20 ` Alan Cox
2011-12-12 17:20 ` Ingo Molnar
2011-12-12 18:16 ` Avi Kivity
2011-12-12 18:16 ` Avi Kivity
2011-12-12 21:36 ` Alan Cox
2011-12-13 10:32 ` Avi Kivity
2011-12-12 11:23 ` Cyrill Gorcunov
2011-12-12 17:40 ` Sasha Levin
2011-12-12 17:45 ` Ingo Molnar
2011-12-12 9:42 ` Thomas Gleixner
2011-12-12 11:19 ` Pekka Enberg
2011-12-12 17:20 ` Ingo Molnar
2011-12-12 18:40 ` Pekka Enberg
2011-12-12 19:14 ` Pekka Enberg
2011-12-12 19:21 ` Ingo Molnar
2011-12-13 0:59 ` Thomas Gleixner
2011-12-13 7:03 ` Pekka Enberg
2011-12-13 11:05 ` Alan Cox
2011-12-13 10:58 ` Avi Kivity
2011-12-13 13:52 ` Thomas Gleixner
2011-12-13 14:23 ` Avi Kivity
2011-12-13 14:30 ` Sasha Levin
2011-12-13 14:51 ` Thomas Gleixner
2011-12-13 14:58 ` Avi Kivity
2011-12-12 21:03 ` James Courtier-Dutton
2011-12-12 18:19 ` Avi Kivity
2011-12-12 18:31 ` Pekka Enberg
2011-12-13 10:33 ` Avi Kivity
2011-12-12 10:27 ` Alan Cox
2011-12-12 10:59 ` Sasha Levin
2011-12-12 11:02 ` Alan Cox
2011-12-12 18:21 ` Avi Kivity
2011-12-12 17:21 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111210132439.049356768@linutronix.de \
--to=tglx@linutronix.de \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®