From nobody Tue Dec 30 12:58:07 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC8FCC197A0 for ; Thu, 16 Nov 2023 10:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345020AbjKPKbh (ORCPT ); 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=C3=A9o 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-pl01= 1.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; } =20 +static void pl011_maybe_set_bit(bool cond, unsigned int *ptr, unsigned int= mask) +{ + if (cond) + *ptr |=3D mask; +} + static unsigned int pl011_get_mctrl(struct uart_port *port) { struct uart_amba_port *uap =3D @@ -1601,18 +1607,22 @@ static unsigned int pl011_get_mctrl(struct uart_por= t *port) unsigned int result =3D 0; unsigned int status =3D pl011_read(uap, REG_FR); =20 -#define TIOCMBIT(uartbit, tiocmbit) \ - if (status & uartbit) \ - result |=3D 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); =20 - 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; } =20 +static void pl011_assign_bit(bool cond, unsigned int *ptr, unsigned int ma= sk) +{ + if (cond) + *ptr |=3D mask; + else + *ptr &=3D ~mask; +} + static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) { struct uart_amba_port *uap =3D @@ -1621,23 +1631,16 @@ static void pl011_set_mctrl(struct uart_port *port,= unsigned int mctrl) =20 cr =3D pl011_read(uap, REG_CR); =20 -#define TIOCMBIT(tiocmbit, uartbit) \ - if (mctrl & tiocmbit) \ - cr |=3D uartbit; \ - else \ - cr &=3D ~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); =20 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 =20 pl011_write(cr, uap, REG_CR); } --=20 2.41.0