Received: by 10.213.65.68 with SMTP id h4csp815984imn; Fri, 23 Mar 2018 17:34:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELs4+Oq287sBG2nOOFjd2KYYJrxfyFmxW3YEAh1YTisz/J1jfNGuzTcJJGwsv2dSZj0O/zor X-Received: by 2002:a17:902:b905:: with SMTP id bf5-v6mr838007plb.159.1521851695037; Fri, 23 Mar 2018 17:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521851695; cv=none; d=google.com; s=arc-20160816; b=RgZ4FXP0AMVNKvnpMd4k9e05N3BGpeRQLEMalnjJLlNkOn76z1ftwaUwGi+CQslAP7 XqtMSKYWTfKyN7pOao5sheino59gwCi+P+iPBbeMKhX263nvJV8LdtYXlCbajExbXjwW vM+fZxmVB3s8K0scUVBzrx3VwueT4RmMtp1S/Jy1kqdrmvibtR6td/D/QbVrfvIhxYf0 V7u/vH1jrgerPxgTHfWtaFfbrkKRLBCa8joKNdukAEUHBS3jzYGsIa0FvfK+2ASlTz4H PpZPnm3R2SeCmklantvMCo0gZjsFywZRXIhsJnEiCYQAoXowP8uAxUlR5tE1ZmTbA3Dv SE3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=zGYTGc5YYf2xixTp847E6evxuKfoqAKbbnXQrl+hgwk=; b=CK6b7H4JPWuejKj1LztXn1Tt7jALRgP1Ph0Lcn2aXSqUaUL9SIfF//Z/I/LMNHut1N 4RnzIaNWLsJtB6fGeW+FUrhOesBur7I4g2f3dNWYuT1e15oCVsESyGb0GKZa8Ve7oKBo 6b6NC0vjeyF9dRc68mUrS3i6/O97q7woQUgPlyuS5ySN/FjG8+Od8ICUfyLjO9b9ndF3 0Zeimd7UMPNDkbhVyljIKY4xs50Bg/idsd7EgLJ4oly2l5GrvE4DQir/c6c3Cn1zVMen s0eCHYZIo5hKiJiqcZIwzXT36OioybsuUx2frCm+K6f4hMWQSrI6EoaJcv79ywd48vSs zBpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZWppoNZj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si7433776ple.556.2018.03.23.17.34.40; Fri, 23 Mar 2018 17:34:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZWppoNZj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752119AbeCXAbx (ORCPT + 99 others); Fri, 23 Mar 2018 20:31:53 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:46360 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751999AbeCXAbl (ORCPT ); Fri, 23 Mar 2018 20:31:41 -0400 Received: by mail-pg0-f66.google.com with SMTP id t12so3411884pgp.13 for ; Fri, 23 Mar 2018 17:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zGYTGc5YYf2xixTp847E6evxuKfoqAKbbnXQrl+hgwk=; b=ZWppoNZjpIL4mvRzi+1xzXVx2XdFnghRQSnvRoN7cl+nfm/q6Z2y976Lo/hlmruqVH fM8wrVwgq04tTgjxUgcTtFZ0mk0s8yU4xIccCsg+7XWox84EL2l0wshz99cbuYWukxxm EKIXZLGGjaVlhFIpmrF7BdTi+MEsasDATTWQoqM3uu5+erwc+3lcnUWUMEdyQGy7If/h o4Pwtk7J7vqQlrOUYAIy9AkADVpaN7Iwlq1SgCeCk52uYxTw1rlsJt6ZC3aI3PjVAMmi +6H4pg8UprqCZGtUabdmSZRSu6YfJWiM+oyGQaOuaiIm2A7lgjpxFY1O6/slCsie8O0l keIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zGYTGc5YYf2xixTp847E6evxuKfoqAKbbnXQrl+hgwk=; b=poE+N/rlVzE0h7VUatcZeqAqI7XSqdo/wAJKwVbrAkxw0hQcpMoc4TP0KMatuzto1j w2tQql3t37gYdqIDAkshSerQdvb9lpHzPN62AJT95aAduiq6JFa/OaUwtYdgNlbBJQ6F sG2XCB6HYeSKR9EUgsHrRuZr4IWP3gKtMEQEnOJFRCdyFkfOMMbzzY3DroswzuaYePu4 hzfdahYuvcer2NkJOrchFOJvFVxqUEjT3Qp0n7An8ltbOmL82YwFgU06RNjwPniZJ1Sr J3AMmo/6Jb0uQaGM6iXkrKsN5QQc4mk6B2uJOtLBWQbQ00S+sIpjLYXhJ/igvtwfOmQp 8faw== X-Gm-Message-State: AElRT7Es3EnGRRnrwhI1gJ5AyyRyOWQAVOKObQxjHqeyW3GUIZVyHGfM Jo2DQBMJRPDlyxFAFCVShub+7A== X-Received: by 10.99.181.10 with SMTP id y10mr22752444pge.222.1521851500745; Fri, 23 Mar 2018 17:31:40 -0700 (PDT) Received: from nibbler.alyptik.lan ([2605:e000:1117:c19a:2e0:1bff:fe70:ea]) by smtp.gmail.com with ESMTPSA id y27sm19682943pfi.156.2018.03.23.17.31.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Mar 2018 17:31:39 -0700 (PDT) From: Joey Pabalinas To: linux-kernel@vger.kernel.org Cc: Joey Pabalinas Subject: [PATCH 4/4] tty/nozomi: refactor conditional statements Date: Fri, 23 Mar 2018 14:31:27 -1000 Message-Id: <20180324003127.4287-5-joeypabalinas@gmail.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180324003127.4287-1-joeypabalinas@gmail.com> References: <20180324003127.4287-1-joeypabalinas@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reduce unnecessarily deep nesting of blocks and simplify control flow (e.g. "if/else" constructs changed to "if/return" and single case "switch" statements changed to "if" conditionals where possible). Signed-off-by: Joey Pabalinas 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index a5074a59d3e3d33e68..0ea3e1de23c093e808 100644 --- a/drivers/tty/nozomi.c +++ b/drivers/tty/nozomi.c @@ -694,12 +694,13 @@ static void enable_transmit_ul(enum port_type port, struct nozomi *dc) { static const u16 mask[] = {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL}; - if (port < NOZOMI_MAX_PORTS) { - dc->last_ier |= mask[port]; - writew(dc->last_ier, dc->reg_ier); - } else { + if (port >= NOZOMI_MAX_PORTS) { dev_err(&dc->pdev->dev, "Called with wrong port?\n"); + return; } + + dc->last_ier |= mask[port]; + writew(dc->last_ier, dc->reg_ier); } /* Disable uplink interrupts */ @@ -708,12 +709,13 @@ static void disable_transmit_ul(enum port_type port, struct nozomi *dc) static const u16 mask[] = {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL}; - if (port < NOZOMI_MAX_PORTS) { - dc->last_ier &= mask[port]; - writew(dc->last_ier, dc->reg_ier); - } else { + if (port >= NOZOMI_MAX_PORTS) { dev_err(&dc->pdev->dev, "Called with wrong port?\n"); + return; } + + dc->last_ier &= mask[port]; + writew(dc->last_ier, dc->reg_ier); } /* Enable downlink interrupts */ @@ -721,12 +723,13 @@ static void enable_transmit_dl(enum port_type port, struct nozomi *dc) { static const u16 mask[] = {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL}; - if (port < NOZOMI_MAX_PORTS) { - dc->last_ier |= mask[port]; - writew(dc->last_ier, dc->reg_ier); - } else { + if (port >= NOZOMI_MAX_PORTS) { dev_err(&dc->pdev->dev, "Called with wrong port?\n"); + return; } + + dc->last_ier |= mask[port]; + writew(dc->last_ier, dc->reg_ier); } /* Disable downlink interrupts */ @@ -735,12 +738,13 @@ static void disable_transmit_dl(enum port_type port, struct nozomi *dc) static const u16 mask[] = {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL}; - if (port < NOZOMI_MAX_PORTS) { - dc->last_ier &= mask[port]; - writew(dc->last_ier, dc->reg_ier); - } else { + if (port >= NOZOMI_MAX_PORTS) { dev_err(&dc->pdev->dev, "Called with wrong port?\n"); + return; } + + dc->last_ier &= mask[port]; + writew(dc->last_ier, dc->reg_ier); } /* @@ -1028,33 +1032,31 @@ static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle, if (*toggle == 0 && read_iir & mask1) { if (receive_data(port, dc)) { writew(mask1, dc->reg_fcr); - *toggle = !(*toggle); + *toggle = !*toggle; } - if (read_iir & mask2) { - if (receive_data(port, dc)) { - writew(mask2, dc->reg_fcr); - *toggle = !(*toggle); - } + if (read_iir & mask2 && receive_data(port, dc)) { + writew(mask2, dc->reg_fcr); + *toggle = !*toggle; } + + return 1; } else if (*toggle == 1 && read_iir & mask2) { if (receive_data(port, dc)) { writew(mask2, dc->reg_fcr); - *toggle = !(*toggle); + *toggle = !*toggle; } - if (read_iir & mask1) { - if (receive_data(port, dc)) { - writew(mask1, dc->reg_fcr); - *toggle = !(*toggle); - } + if (read_iir & mask1 && receive_data(port, dc)) { + writew(mask1, dc->reg_fcr); + *toggle = !*toggle; } - } else { - dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n", - *toggle); - return 0; + + return 1; } - return 1; + + dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n", *toggle); + return 0; } /* @@ -1087,6 +1089,7 @@ static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir) } } + return 1; } else if (*toggle == 1 && read_iir & MDM_UL2) { dc->last_ier &= ~MDM_UL; writew(dc->last_ier, dc->reg_ier); @@ -1107,12 +1110,13 @@ static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir) *toggle = !*toggle; } } - } else { - writew(read_iir & MDM_UL, dc->reg_fcr); - dev_err(&dc->pdev->dev, "port out of sync!\n"); - return 0; + + return 1; } - return 1; + + writew(read_iir & MDM_UL, dc->reg_fcr); + dev_err(&dc->pdev->dev, "port out of sync!\n"); + return 0; } static irqreturn_t interrupt_handler(int irq, void *dev_id) @@ -1121,7 +1125,7 @@ static irqreturn_t interrupt_handler(int irq, void *dev_id) unsigned int i; u16 read_iir; - if (!dc) + if (unlikely(!dc)) return IRQ_NONE; spin_lock(&dc->spin_mutex); @@ -1344,8 +1348,9 @@ static int nozomi_card_init(struct pci_dev *pdev, ret = pci_request_regions(dc->pdev, NOZOMI_NAME); if (ret) { - /* nozomi_private.io_addr */ - dev_err(&pdev->dev, "I/O address 0x%04x already in use\n", 0); + dev_err(&pdev->dev, "I/O address 0x%04x already in use\n", + /* (int) nozomi_private.io_addr */ 0); + goto err_disable_device; } @@ -1752,18 +1757,15 @@ static int ntty_ioctl(struct tty_struct *tty, DBG1("******** IOCTL, cmd: %d", cmd); - switch (cmd) { - case TIOCMIWAIT: { - struct async_icount cprev = port->tty_icount; - rval = wait_event_interruptible(port->tty_wait, - ntty_cflags_changed(port, arg, &cprev)); - break; - } - default: + if (cmd != TIOCMIWAIT) { DBG1("ERR: 0x%08X, %d", cmd, cmd); - break; + goto no_ioctl; } + rval = wait_event_interruptible(port->tty_wait, + ntty_cflags_changed(port, arg, &port->tty_icount)); + +no_ioctl: return rval; } -- 2.16.3