diff mbox series

[v2,4/4] serial: exar: remove ternaries from cti_get_port_type_xr17c15x_xr17v25x()

Message ID d672326427b1026c7700303eedef8594f2688def.1713533298.git.pnewman@connecttech.com
State New
Headers show
Series serial: exar: fix kbuild warnings and code style | expand

Commit Message

Parker Newman April 19, 2024, 2:17 p.m. UTC
From: Parker Newman <pnewman@connecttech.com>

Remove ternary operators from cti_get_port_type_xr17c15x_xr17v25x() for
better readability.

Signed-off-by: Parker Newman <pnewman@connecttech.com>
---
Changes in v2:
- Removed ternary operators completely

 drivers/tty/serial/8250/8250_exar.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

--
2.43.2

Comments

Jiri Slaby April 22, 2024, 6:34 a.m. UTC | #1
On 19. 04. 24, 16:17, Parker Newman wrote:
> From: Parker Newman <pnewman@connecttech.com>
> 
> Remove ternary operators from cti_get_port_type_xr17c15x_xr17v25x() for
> better readability.
> 
> Signed-off-by: Parker Newman <pnewman@connecttech.com>

Much better.

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

> --- a/drivers/tty/serial/8250/8250_exar.c
> +++ b/drivers/tty/serial/8250/8250_exar.c
> @@ -726,7 +726,7 @@ static enum cti_port_type cti_get_port_type_xr17c15x_xr17v25x(struct exar8250 *p
>   							struct pci_dev *pcidev,
>   							unsigned int port_num)
>   {
> -	enum cti_port_type port_type;
> +	enum cti_port_type port_type = CTI_PORT_TYPE_RS232;
> 
>   	switch (pcidev->subsystem_device) {
>   	// RS232 only cards

Unrelated to this one, but // comments are discouraged in the kernel, IMO?

thanks,
diff mbox series

Patch

diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
index 8665d3b7b673..521d2acf4004 100644
--- a/drivers/tty/serial/8250/8250_exar.c
+++ b/drivers/tty/serial/8250/8250_exar.c
@@ -726,7 +726,7 @@  static enum cti_port_type cti_get_port_type_xr17c15x_xr17v25x(struct exar8250 *p
 							struct pci_dev *pcidev,
 							unsigned int port_num)
 {
-	enum cti_port_type port_type;
+	enum cti_port_type port_type = CTI_PORT_TYPE_RS232;

 	switch (pcidev->subsystem_device) {
 	// RS232 only cards
@@ -737,23 +737,22 @@  static enum cti_port_type cti_get_port_type_xr17c15x_xr17v25x(struct exar8250 *p
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_SP_232_NS:
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP_232:
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP_232_NS:
-		port_type = CTI_PORT_TYPE_RS232;
 		break;
 	// 1x RS232, 1x RS422/RS485
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_1_1:
-		port_type = (port_num == 0) ?
-			CTI_PORT_TYPE_RS232 : CTI_PORT_TYPE_RS422_485;
+		if (port_num)
+			port_type = CTI_PORT_TYPE_RS422_485;
 		break;
 	// 2x RS232, 2x RS422/RS485
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_2:
-		port_type = (port_num < 2) ?
-			CTI_PORT_TYPE_RS232 : CTI_PORT_TYPE_RS422_485;
+		if (port_num > 1)
+			port_type = CTI_PORT_TYPE_RS422_485;
 		break;
 	// 4x RS232, 4x RS422/RS485
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_4:
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_4_SP:
-		port_type = (port_num < 4) ?
-			CTI_PORT_TYPE_RS232 : CTI_PORT_TYPE_RS422_485;
+		if (port_num > 3)
+			port_type = CTI_PORT_TYPE_RS422_485;
 		break;
 	// RS232/RS422/RS485 HW (jumper) selectable
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2:
@@ -789,13 +788,13 @@  static enum cti_port_type cti_get_port_type_xr17c15x_xr17v25x(struct exar8250 *p
 		break;
 	// 6x RS232, 2x RS422/RS485
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_6_2_SP:
-		port_type = (port_num < 6) ?
-			CTI_PORT_TYPE_RS232 : CTI_PORT_TYPE_RS422_485;
+		if (port_num > 5)
+			port_type = CTI_PORT_TYPE_RS422_485;
 		break;
 	// 2x RS232, 6x RS422/RS485
 	case PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_6_SP:
-		port_type = (port_num < 2) ?
-			CTI_PORT_TYPE_RS232 : CTI_PORT_TYPE_RS422_485;
+		if (port_num > 1)
+			port_type = CTI_PORT_TYPE_RS422_485;
 		break;
 	default:
 		dev_err(&pcidev->dev, "unknown/unsupported device\n");