Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1306908

[PATCH LINUX 3/6] tty: xuartps: Cleanup: Reformat if-else

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Soren Brinkmann <soren.brinkmann@xilinx.com>
Newsgroups linux.kernel
Subject [PATCH LINUX 3/6] tty: xuartps: Cleanup: Reformat if-else
Date Tue, 12 Jan 2016 02:50:01 +0100
Message-ID <qPWfT-2p4-9@gated-at.bofh.it> (permalink)
References <qPWfT-2p4-3@gated-at.bofh.it>
Authentication-Results spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; hurleysoftware.com; dkim=none (message not signed) header.d=none;hurleysoftware.com; dmarc=bestguesspass action=none header.from=xilinx.com;
Received-Spf Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01;
X-Mailer git-send-email 2.7.0.3.g497ea1e
X-Rcis-Action ALLOW
X-Tm-As-Product-Ver IMSS-7.1.0.1224-8.0.0.1202-22058.006
X-Tm-As-User-Approved-Sender Yes;Yes
X-Forefront-Antispam-Report CIP:149.199.60.83;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(189002)(199003)(5001960100002)(57986006)(5008740100001)(50226001)(6806005)(4001430100002)(1220700001)(81156007)(86362001)(586003)(1096002)(5001770100001)(76176999)(4326007)(36386004)(2906002)(189998001)(107886002)(50466002)(47776003)(11100500001)(2950100001)(5003940100001)(229853001)(76506005)(48376002)(77096005)(50986999)(87936001)(19580395003)(36756003)(92566002)(106466001)(33646002)(19580405001)(63266004)(107986001)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1NAM02HT009;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;PTR:unknown-60-83.xilinx.com;MX:1;A:1;LANG:en;
MIME-Version 1.0
Content-Type text/plain
X-Ms-Office365-Filtering-Correlation-ID a32535f8-558e-4bd2-ffc7-08d31af18edf
X-Exchange-Antispam-Report-Test UriScan:;BCL:0;PCL:0;RULEID:(8251501002);SRVR:SN1NAM02HT009;UriScan:(192813158149592);
X-Microsoft-Antispam-Prvs <8e2bb1291cb14156bb14880ea6eaa6bd@SN1NAM02HT009.eop-nam02.prod.protection.outlook.com>
X-Exchange-Antispam-Report-Cfa-Test BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(13018025)(520078)(13015025)(13017025)(10201501046)(3002001);SRVR:SN1NAM02HT009;BCL:0;PCL:0;RULEID:;SRVR:SN1NAM02HT009;
X-Forefront-Prvs 081904387B
X-Originatororg xilinx.com
X-Ms-Exchange-Crosstenant-Originalarrivaltime 12 Jan 2016 01:41:57.2575 (UTC)
X-Ms-Exchange-Crosstenant-ID 657af505-d5df-48d0-8300-c31994686c5c
X-Ms-Exchange-Crosstenant-Originalattributedtenantconnectingip TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01]
X-Ms-Exchange-Crosstenant-Fromentityheader HybridOnPrem
X-Ms-Exchange-Transport-Crosstenantheadersstamped SN1NAM02HT009
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 163
Organization linux.* mail to news gateway
X-Original-Cc Michal Simek <michal.simek@xilinx.com>, <linux-serial@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, "Peter Hurley" <peter@hurleysoftware.com>, Soren Brinkmann <soren.brinkmann@xilinx.com>
X-Original-Date Mon, 11 Jan 2016 17:41:38 -0800
X-Original-Message-ID <1452562901-17848-4-git-send-email-soren.brinkmann@xilinx.com>
X-Original-References <1452562901-17848-1-git-send-email-soren.brinkmann@xilinx.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1306908

Show key headers only | View raw


Convert an if-else into the more common early return on error, reducing
the indent level of the happy path.

Signed-off-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
---
 drivers/tty/serial/xilinx_uartps.c | 124 ++++++++++++++++++-------------------
 1 file changed, 62 insertions(+), 62 deletions(-)

diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index a0039cbcf812..8014dd3c6d55 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -202,58 +202,55 @@ static void cdns_uart_handle_rx(struct uart_port *port, unsigned int isrstatus)
 	isrstatus &= port->read_status_mask;
 	isrstatus &= ~port->ignore_status_mask;
 
-	if ((isrstatus & CDNS_UART_IXR_TOUT) ||
-		(isrstatus & CDNS_UART_IXR_RXTRIG)) {
-		/* Receive Timeout Interrupt */
-		while (!(readl(port->membase + CDNS_UART_SR_OFFSET) &
-					CDNS_UART_SR_RXEMPTY)) {
-			u32 data;
-			char status = TTY_NORMAL;
-
-			data = readl(port->membase + CDNS_UART_FIFO_OFFSET);
-
-			/* Non-NULL byte after BREAK is garbage (99%) */
-			if (data && (port->read_status_mask &
-						CDNS_UART_IXR_BRK)) {
-				port->read_status_mask &= ~CDNS_UART_IXR_BRK;
-				port->icount.brk++;
-				if (uart_handle_break(port))
-					continue;
-			}
+	if (!(isrstatus & (CDNS_UART_IXR_TOUT | CDNS_UART_IXR_RXTRIG)))
+		return;
+
+	while (!(readl(port->membase + CDNS_UART_SR_OFFSET) &
+				CDNS_UART_SR_RXEMPTY)) {
+		u32 data;
+		char status = TTY_NORMAL;
+
+		data = readl(port->membase + CDNS_UART_FIFO_OFFSET);
+
+		/* Non-NULL byte after BREAK is garbage (99%) */
+		if (data && (port->read_status_mask & CDNS_UART_IXR_BRK)) {
+			port->read_status_mask &= ~CDNS_UART_IXR_BRK;
+			port->icount.brk++;
+			if (uart_handle_break(port))
+				continue;
+		}
 
 #ifdef SUPPORT_SYSRQ
-			/*
-			 * uart_handle_sysrq_char() doesn't work if
-			 * spinlocked, for some reason
-			 */
-			 if (port->sysrq) {
-				spin_unlock(&port->lock);
-				if (uart_handle_sysrq_char(port,
-							(unsigned char)data)) {
-					spin_lock(&port->lock);
-					continue;
-				}
+		/*
+		 * uart_handle_sysrq_char() doesn't work if
+		 * spinlocked, for some reason
+		 */
+		 if (port->sysrq) {
+			spin_unlock(&port->lock);
+			if (uart_handle_sysrq_char(port, data)) {
 				spin_lock(&port->lock);
+				continue;
 			}
+			spin_lock(&port->lock);
+		}
 #endif
 
-			port->icount.rx++;
-
-			if (isrstatus & CDNS_UART_IXR_PARITY) {
-				port->icount.parity++;
-				status = TTY_PARITY;
-			} else if (isrstatus & CDNS_UART_IXR_FRAMING) {
-				port->icount.frame++;
-				status = TTY_FRAME;
-			} else if (isrstatus & CDNS_UART_IXR_OVERRUN) {
-				port->icount.overrun++;
-			}
+		port->icount.rx++;
 
-			uart_insert_char(port, isrstatus, CDNS_UART_IXR_OVERRUN,
-					 data, status);
+		if (isrstatus & CDNS_UART_IXR_PARITY) {
+			port->icount.parity++;
+			status = TTY_PARITY;
+		} else if (isrstatus & CDNS_UART_IXR_FRAMING) {
+			port->icount.frame++;
+			status = TTY_FRAME;
+		} else if (isrstatus & CDNS_UART_IXR_OVERRUN) {
+			port->icount.overrun++;
 		}
-		tty_flip_buffer_push(&port->state->port);
+
+		uart_insert_char(port, isrstatus, CDNS_UART_IXR_OVERRUN,
+				 data, status);
 	}
+	tty_flip_buffer_push(&port->state->port);
 }
 
 /**
@@ -1429,27 +1426,30 @@ static int cdns_uart_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Cannot get uart_port structure\n");
 		rc = -ENODEV;
 		goto err_out_notif_unreg;
-	} else {
-		/* Register the port.
-		 * This function also registers this device with the tty layer
-		 * and triggers invocation of the config_port() entry point.
-		 */
-		port->mapbase = res->start;
-		port->irq = irq;
-		port->dev = &pdev->dev;
-		port->uartclk = clk_get_rate(cdns_uart_data->uartclk);
-		port->private_data = cdns_uart_data;
-		cdns_uart_data->port = port;
-		platform_set_drvdata(pdev, port);
-		rc = uart_add_one_port(&cdns_uart_uart_driver, port);
-		if (rc) {
-			dev_err(&pdev->dev,
-				"uart_add_one_port() failed; err=%i\n", rc);
-			goto err_out_notif_unreg;
-		}
-		return 0;
 	}
 
+	/*
+	 * Register the port.
+	 * This function also registers this device with the tty layer
+	 * and triggers invocation of the config_port() entry point.
+	 */
+	port->mapbase = res->start;
+	port->irq = irq;
+	port->dev = &pdev->dev;
+	port->uartclk = clk_get_rate(cdns_uart_data->uartclk);
+	port->private_data = cdns_uart_data;
+	cdns_uart_data->port = port;
+	platform_set_drvdata(pdev, port);
+
+	rc = uart_add_one_port(&cdns_uart_uart_driver, port);
+	if (rc) {
+		dev_err(&pdev->dev,
+			"uart_add_one_port() failed; err=%i\n", rc);
+		goto err_out_notif_unreg;
+	}
+
+	return 0;
+
 err_out_notif_unreg:
 #ifdef CONFIG_COMMON_CLK
 	clk_notifier_unregister(cdns_uart_data->uartclk,
-- 
2.7.0.3.g497ea1e

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH LINUX 3/6] tty: xuartps: Cleanup: Reformat if-else Soren Brinkmann <soren.brinkmann@xilinx.com> - 2016-01-12 02:50 +0100

csiph-web