serial: switch uart_port::iotype to enum uart_iotype
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Fri, 25 Apr 2025 11:13:12 +0000 (13:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 11:46:31 +0000 (13:46 +0200)
The inline-defined constants look weird. Instead, define a proper enum
for them and type uart_port::iotype as that enum. This allows for proper
checking in switch-case labels (somewhere, a default or UPIO_UNKNOWN
label needs to be added/handled).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250425111315.1036184-4-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_core.c
drivers/tty/serial/8250/8250_early.c
drivers/tty/serial/8250/8250_port.c
drivers/tty/serial/8250/8250_rsa.c
drivers/tty/serial/amba-pl011.c
drivers/tty/serial/fsl_lpuart.c
drivers/tty/serial/samsung_tty.c
drivers/tty/serial/serial_core.c
include/linux/serial_core.h

index 5a56f853cf6d8c9a418280b60fa134ea30faa3bb..68994a964321f137798e09b163c7cd318010ee20 100644 (file)
@@ -461,7 +461,7 @@ static int univ8250_console_match(struct console *co, char *name, int idx,
                                  char *options)
 {
        char match[] = "uart";  /* 8250-specific earlycon name */
-       unsigned char iotype;
+       enum uart_iotype iotype;
        resource_size_t addr;
        int i;
 
index 84242292176570cd2c92afbd4755d303827a4abc..dc0371857ecbee7149d5f95277b756869bc80a66 100644 (file)
@@ -77,6 +77,8 @@ static void serial8250_early_out(struct uart_port *port, int offset, int value)
                outb(value, port->iobase + offset);
                break;
 #endif
+       default:
+               break;
        }
 }
 
index 8ac452cea36c6ea0f3f0af5df99ac5ce10a8b1af..8d9bb91d4bae54e88c64e8b5e065c659bb81ae63 100644 (file)
@@ -2993,6 +2993,8 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
                if (!request_region(port->iobase, size, "serial"))
                        return -EBUSY;
                return 0;
+       case UPIO_UNKNOWN:
+               break;
        }
 
        return 0;
@@ -3025,6 +3027,8 @@ static void serial8250_release_std_resource(struct uart_8250_port *up)
        case UPIO_PORT:
                release_region(port->iobase, size);
                break;
+       case UPIO_UNKNOWN:
+               break;
        }
 }
 
index 82f2593b4c59b39e08022cd08d4e8a2fd649a708..4c8b9671bd41d77ee8790e01d7c96a35c7b9436f 100644 (file)
@@ -43,6 +43,8 @@ static void rsa8250_release_resource(struct uart_8250_port *up)
        case UPIO_PORT:
                release_region(port->iobase + offset, size);
                break;
+       default:
+               break;
        }
 }
 
index 11d65097578cd335541e9c8d55cf3573b651fe8d..421ac22555dffb87eff3b56867fe23e10855848a 100644 (file)
@@ -2476,7 +2476,7 @@ static int pl011_console_setup(struct console *co, char *options)
 static int pl011_console_match(struct console *co, char *name, int idx,
                               char *options)
 {
-       unsigned char iotype;
+       enum uart_iotype iotype;
        resource_size_t addr;
        int i;
 
index fe5aed99d55a664b5fa20f306ced712e41b6f408..dff6a6c57b5f71900afaa521efa9e465c74bc07d 100644 (file)
@@ -403,6 +403,8 @@ static inline void lpuart32_write(struct uart_port *port, u32 val,
        case UPIO_MEM32BE:
                iowrite32be(val, port->membase + off);
                break;
+       default:
+               break;
        }
 }
 
@@ -563,8 +565,9 @@ static dma_addr_t lpuart_dma_datareg_addr(struct lpuart_port *sport)
                return sport->port.mapbase + UARTDATA;
        case UPIO_MEM32BE:
                return sport->port.mapbase + UARTDATA + sizeof(u32) - 1;
+       default:
+               return sport->port.mapbase + UARTDR;
        }
-       return sport->port.mapbase + UARTDR;
 }
 
 static int lpuart_dma_tx_request(struct uart_port *port)
index 210fff7164c138e315d20ccaa4a29ce6a7bb2dfe..73e2866febc193473e7f70daf30e9cc76edfbc7c 100644 (file)
@@ -190,6 +190,8 @@ static void wr_reg(const struct uart_port *port, u32 reg, u32 val)
        case UPIO_MEM32:
                writel_relaxed(val, portaddr(port, reg));
                break;
+       default:
+               break;
        }
 }
 
@@ -2713,6 +2715,8 @@ static void wr_reg_barrier(const struct uart_port *port, u32 reg, u32 val)
        case UPIO_MEM32:
                writel(val, portaddr(port, reg));
                break;
+       default:
+               break;
        }
 }
 
index 88669972d9a036ec2f8e13bf421fab6816512611..5bc14564338520ebba8a93c0c235dfd43d089448 100644 (file)
@@ -2178,8 +2178,8 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co)
  *
  * Returns: 0 on success or -%EINVAL on failure
  */
-int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,
-                       char **options)
+int uart_parse_earlycon(char *p, enum uart_iotype *iotype,
+                       resource_size_t *addr, char **options)
 {
        if (strncmp(p, "mmio,", 5) == 0) {
                *iotype = UPIO_MEM;
@@ -3289,9 +3289,9 @@ bool uart_match_port(const struct uart_port *port1,
        case UPIO_AU:
        case UPIO_TSI:
                return port1->mapbase == port2->mapbase;
+       default:
+               return false;
        }
-
-       return false;
 }
 EXPORT_SYMBOL(uart_match_port);
 
index 743b4afaad4c89a6028e592be2cae2643614c89b..914b5e97e05647dfa02d8dfb0d231bfcd0c945f8 100644 (file)
@@ -427,6 +427,18 @@ struct uart_icount {
 typedef u64 __bitwise upf_t;
 typedef unsigned int __bitwise upstat_t;
 
+enum uart_iotype {
+       UPIO_UNKNOWN    = -1,
+       UPIO_PORT       = SERIAL_IO_PORT,       /* 8b I/O port access */
+       UPIO_HUB6       = SERIAL_IO_HUB6,       /* Hub6 ISA card */
+       UPIO_MEM        = SERIAL_IO_MEM,        /* driver-specific */
+       UPIO_MEM32      = SERIAL_IO_MEM32,      /* 32b little endian */
+       UPIO_AU         = SERIAL_IO_AU,         /* Au1x00 and RT288x type IO */
+       UPIO_TSI        = SERIAL_IO_TSI,        /* Tsi108/109 type IO */
+       UPIO_MEM32BE    = SERIAL_IO_MEM32BE,    /* 32b big endian */
+       UPIO_MEM16      = SERIAL_IO_MEM16,      /* 16b little endian */
+};
+
 struct uart_port {
        spinlock_t              lock;                   /* port lock */
        unsigned long           iobase;                 /* in/out[bwl] */
@@ -469,23 +481,13 @@ struct uart_port {
        unsigned char           x_char;                 /* xon/xoff char */
        unsigned char           regshift;               /* reg offset shift */
 
-       unsigned char           iotype;                 /* io access style */
-
-#define UPIO_UNKNOWN           ((unsigned char)~0U)    /* UCHAR_MAX */
-#define UPIO_PORT              (SERIAL_IO_PORT)        /* 8b I/O port access */
-#define UPIO_HUB6              (SERIAL_IO_HUB6)        /* Hub6 ISA card */
-#define UPIO_MEM               (SERIAL_IO_MEM)         /* driver-specific */
-#define UPIO_MEM32             (SERIAL_IO_MEM32)       /* 32b little endian */
-#define UPIO_AU                        (SERIAL_IO_AU)          /* Au1x00 and RT288x type IO */
-#define UPIO_TSI               (SERIAL_IO_TSI)         /* Tsi108/109 type IO */
-#define UPIO_MEM32BE           (SERIAL_IO_MEM32BE)     /* 32b big endian */
-#define UPIO_MEM16             (SERIAL_IO_MEM16)       /* 16b little endian */
-
        unsigned char           quirks;                 /* internal quirks */
 
        /* internal quirks must be updated while holding port mutex */
 #define UPQ_NO_TXEN_TEST       BIT(0)
 
+       enum uart_iotype        iotype;                 /* io access style */
+
        unsigned int            read_status_mask;       /* driver specific */
        unsigned int            ignore_status_mask;     /* driver specific */
        struct uart_state       *state;                 /* pointer to parent state */
@@ -1101,8 +1103,8 @@ static inline bool uart_console_registered(struct uart_port *port)
 
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
                                   struct console *c);
-int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,
-                       char **options);
+int uart_parse_earlycon(char *p, enum uart_iotype *iotype,
+                       resource_size_t *addr, char **options);
 void uart_parse_options(const char *options, int *baud, int *parity, int *bits,
                        int *flow);
 int uart_set_options(struct uart_port *port, struct console *co, int baud,