From patchwork Thu Nov 16 10:31:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 165748 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp3118148vqg; Thu, 16 Nov 2023 02:32:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYNR7vhSIR2tWaW2hOg9gmF4tWtlF52ZFuOwMQdUsZoBWUfaNyXg3ey30Y98J+EnTVTPGN X-Received: by 2002:a17:90b:3e89:b0:280:74fc:6545 with SMTP id rj9-20020a17090b3e8900b0028074fc6545mr15448999pjb.24.1700130734478; Thu, 16 Nov 2023 02:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700130734; cv=none; d=google.com; s=arc-20160816; b=W4Wz5MHHB2iQwkAAJQWeYQgzxTtaRAYmXdjMoMyTp6p2DknLstnNB0p7SCk3juvQoj lFTmy6L3taKS9E62Pbw3jKTA7NeHLrjH0F7eGRH6limBIfAa18pSCvt18bdyHw1bjgM/ ggzQR96wrUeM2/kHdZMy/E4NxAjZXb9I8hpgRSd1sEWMgEZ8yhY7zggIkv0ne9JWRpBu zZ5RKIv9MoU5ff12DhGStoPlZK7HWmxaAyVPXW1Ja/cBXDkca+U7gMWT1KV36EPdVXPt G/LUkjkqb3WA36qL0AEkBdLoqsodLqA8xzZ6ydriAV0qrf/4Jrufy8/NKvxrFYQtVSnA enBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=4lN48hLGgtpA2K973BPzgWFsxjYsrvJpsG7a0gWgGow=; fh=QQT0ysDV3C9K/ZwUoBeqi9VulQuaknzQuTSh/MRCItc=; b=JatKX2cZ3gV0nhDvSoUzf1gJ4G1ZW0ui9mUx9huIbihCuRs6usaSrVnW/eOSMhsF6k gRMBo8jpgkcXXpPs3UcPb6VI1b9hKNYPNHM8xhjX/nnvCds83dlfeDMeymDLYsJaIyXu h6dn8A9oBSinbq2J13u7Ct19EAlj/EVLHH2qbLVnthBJf9+l3AEzTJjgh4d05dy3OdRx YKzuUGHKP0pKQ8z8EQydcxMO4CqqK9p3Q9Jgy7sv/IToSCcaoWmHg8KZ5RouxVJHfADB xNeqFerVseYPHeg/pTXKUd8UP5f1uKNrL/tXiJpz+dKO/tjik9mN3r1sBRqOr6HHm2kD uUIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="kW5JAA/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q11-20020a170902dacb00b001cc34736568si12484013plx.566.2023.11.16.02.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 02:32:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="kW5JAA/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 08CBC81A1EB7; Thu, 16 Nov 2023 02:31:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345013AbjKPKbh (ORCPT + 29 others); Thu, 16 Nov 2023 05:31:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbjKPKba (ORCPT ); Thu, 16 Nov 2023 05:31:30 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DED2D1; Thu, 16 Nov 2023 02:31:26 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 635AF60010; Thu, 16 Nov 2023 10:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700130684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4lN48hLGgtpA2K973BPzgWFsxjYsrvJpsG7a0gWgGow=; b=kW5JAA/3sAxvjEU8LiacB3LHGZ1xiT4vu56zT+KTrSd8Nui8pdSQL+OD0HcaH+CDvG++h4 tZY1M4iD/g3r/V/k+oEKiVwWiQyGDf6KVQqisqPSk79GQ98c6/Znad7W36Rfhkw2azIyK0 ROBu+2kbKYahO7DliybsDrzUe6xeb9RyXf+w72XC7XcmRKsksvBdbf22oms1115TfBtT2/ 6ZjbupXxboGercs1muPCvhApQCC1GsHTAVSPp7NvL7w3L4WkLjdthfQowZSTy7K7goVCNK 8ePn2UIhBEd/ZJYOIXPuwsLPVssLyzvxj9S3ShbYzl8tuC1V/IhhQH+av7zaKg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 16 Nov 2023 11:31:07 +0100 Subject: [PATCH v2 4/5] tty: serial: amba-pl011: replace TIOCMBIT macros by static functions MIME-Version: 1.0 Message-Id: <20231116-mbly-uart-v2-4-863f665ce520@bootlin.com> References: <20231116-mbly-uart-v2-0-863f665ce520@bootlin.com> In-Reply-To: <20231116-mbly-uart-v2-0-863f665ce520@bootlin.com> To: Russell King , Greg Kroah-Hartman , Jiri Slaby Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Linus Walleij , =?utf-8?q?Gr=C3=A9gory_Clement?= , Alexandre Belloni , Thomas Petazzoni , Vladimir Kondratiev , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.3 X-GND-Sasl: theo.lebrun@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 16 Nov 2023 02:31:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782716284691010448 X-GMAIL-MSGID: 1782716284691010448 The driver uses two TIOCMBIT macros inside pl011_{get,set}_mctrl to simplify the logic. Those look scary to checkpatch because they contain ifs without do-while loops. Avoid the macros by creating small equivalent static functions; that lets the compiler do its type checking & avoids checkpatch errors. For the second instance __assign_bit is not usable because it deals with unsigned long pointers whereas we have an unsigned int in pl011_set_mctrl. Reviewed-by: Linus Walleij Signed-off-by: Théo Lebrun --- drivers/tty/serial/amba-pl011.c | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index d56607957158..bb3082c4d35c 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1594,6 +1594,12 @@ static unsigned int pl011_tx_empty(struct uart_port *port) 0 : TIOCSER_TEMT; } +static void pl011_maybe_set_bit(bool cond, unsigned int *ptr, unsigned int mask) +{ + if (cond) + *ptr |= mask; +} + static unsigned int pl011_get_mctrl(struct uart_port *port) { struct uart_amba_port *uap = @@ -1601,18 +1607,22 @@ static unsigned int pl011_get_mctrl(struct uart_port *port) unsigned int result = 0; unsigned int status = pl011_read(uap, REG_FR); -#define TIOCMBIT(uartbit, tiocmbit) \ - if (status & uartbit) \ - result |= tiocmbit + pl011_maybe_set_bit(status & UART01x_FR_DCD, &result, TIOCM_CAR); + pl011_maybe_set_bit(status & uap->vendor->fr_dsr, &result, TIOCM_DSR); + pl011_maybe_set_bit(status & uap->vendor->fr_cts, &result, TIOCM_CTS); + pl011_maybe_set_bit(status & uap->vendor->fr_ri, &result, TIOCM_RNG); - TIOCMBIT(UART01x_FR_DCD, TIOCM_CAR); - TIOCMBIT(uap->vendor->fr_dsr, TIOCM_DSR); - TIOCMBIT(uap->vendor->fr_cts, TIOCM_CTS); - TIOCMBIT(uap->vendor->fr_ri, TIOCM_RNG); -#undef TIOCMBIT return result; } +static void pl011_assign_bit(bool cond, unsigned int *ptr, unsigned int mask) +{ + if (cond) + *ptr |= mask; + else + *ptr &= ~mask; +} + static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) { struct uart_amba_port *uap = @@ -1621,23 +1631,16 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) cr = pl011_read(uap, REG_CR); -#define TIOCMBIT(tiocmbit, uartbit) \ - if (mctrl & tiocmbit) \ - cr |= uartbit; \ - else \ - cr &= ~uartbit - - TIOCMBIT(TIOCM_RTS, UART011_CR_RTS); - TIOCMBIT(TIOCM_DTR, UART011_CR_DTR); - TIOCMBIT(TIOCM_OUT1, UART011_CR_OUT1); - TIOCMBIT(TIOCM_OUT2, UART011_CR_OUT2); - TIOCMBIT(TIOCM_LOOP, UART011_CR_LBE); + pl011_assign_bit(mctrl & TIOCM_RTS, &cr, UART011_CR_RTS); + pl011_assign_bit(mctrl & TIOCM_DTR, &cr, UART011_CR_DTR); + pl011_assign_bit(mctrl & TIOCM_OUT1, &cr, UART011_CR_OUT1); + pl011_assign_bit(mctrl & TIOCM_OUT2, &cr, UART011_CR_OUT2); + pl011_assign_bit(mctrl & TIOCM_LOOP, &cr, UART011_CR_LBE); if (port->status & UPSTAT_AUTORTS) { /* We need to disable auto-RTS if we want to turn RTS off */ - TIOCMBIT(TIOCM_RTS, UART011_CR_RTSEN); + pl011_assign_bit(mctrl & TIOCM_RTS, &cr, UART011_CR_RTSEN); } -#undef TIOCMBIT pl011_write(cr, uap, REG_CR); }