tty: serial: samsung_tty: do not abuse the struct uart_port unused fields
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Dec 2019 14:02:32 +0000 (15:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Dec 2019 14:09:47 +0000 (15:09 +0100)
The samsung_tty driver was trying to abuse the struct uart_port by using
two "empty" bytes for its own use.  That's not ok, and was found by
removing those fields from the structure.

Move the variables into the port-specific structure, which is where
everything else for this port already is.  There is no space wasted here
as there was an empty "hole" in the structure already for these bytes.

Cc: Kukjin Kim <kgene@kernel.org>
Cc: Hyunki Koo <kkoos00@naver.com>
Cc: HYUN-KI KOO <hyunki00.koo@samsung.com>
Cc: Shinbeom Choi <sbeom.choi@samsung.com>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Dmitry Safonov <dima@arista.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: linux-serial@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Link: https://lore.kernel.org/r/20191217140232.GA3489190@kroah.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/samsung_tty.c

index 2fd4f2d..5b5f249 100644 (file)
 #define S3C24XX_TX_DMA                 2
 #define S3C24XX_RX_PIO                 1
 #define S3C24XX_RX_DMA                 2
-/* macros to change one thing to another */
-
-#define tx_enabled(port) ((port)->unused[0])
-#define rx_enabled(port) ((port)->unused[1])
 
 /* flag to ignore all characters coming in */
 #define RXSTAT_DUMMY_READ (0x10000000)
@@ -123,6 +119,8 @@ struct s3c24xx_uart_dma {
 struct s3c24xx_uart_port {
        unsigned char                   rx_claimed;
        unsigned char                   tx_claimed;
+       unsigned char                   rx_enabled;
+       unsigned char                   tx_enabled;
        unsigned int                    pm_level;
        unsigned long                   baudclk_rate;
        unsigned int                    min_dma_size;
@@ -223,6 +221,7 @@ static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
 
 static void s3c24xx_serial_rx_enable(struct uart_port *port)
 {
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
        unsigned long flags;
        unsigned int ucon, ufcon;
        int count = 10000;
@@ -240,12 +239,13 @@ static void s3c24xx_serial_rx_enable(struct uart_port *port)
        ucon |= S3C2410_UCON_RXIRQMODE;
        wr_regl(port, S3C2410_UCON, ucon);
 
-       rx_enabled(port) = 1;
+       ourport->rx_enabled = 1;
        spin_unlock_irqrestore(&port->lock, flags);
 }
 
 static void s3c24xx_serial_rx_disable(struct uart_port *port)
 {
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
        unsigned long flags;
        unsigned int ucon;
 
@@ -255,7 +255,7 @@ static void s3c24xx_serial_rx_disable(struct uart_port *port)
        ucon &= ~S3C2410_UCON_RXIRQMODE;
        wr_regl(port, S3C2410_UCON, ucon);
 
-       rx_enabled(port) = 0;
+       ourport->rx_enabled = 0;
        spin_unlock_irqrestore(&port->lock, flags);
 }
 
@@ -267,7 +267,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port)
        struct dma_tx_state state;
        int count;
 
-       if (!tx_enabled(port))
+       if (!ourport->tx_enabled)
                return;
 
        if (s3c24xx_serial_has_interrupt_mask(port))
@@ -287,7 +287,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port)
                port->icount.tx += count;
        }
 
-       tx_enabled(port) = 0;
+       ourport->tx_enabled = 0;
        ourport->tx_in_progress = 0;
 
        if (port->flags & UPF_CONS_FLOW)
@@ -445,11 +445,11 @@ static void s3c24xx_serial_start_tx(struct uart_port *port)
        struct s3c24xx_uart_port *ourport = to_ourport(port);
        struct circ_buf *xmit = &port->state->xmit;
 
-       if (!tx_enabled(port)) {
+       if (!ourport->tx_enabled) {
                if (port->flags & UPF_CONS_FLOW)
                        s3c24xx_serial_rx_disable(port);
 
-               tx_enabled(port) = 1;
+               ourport->tx_enabled = 1;
                if (!ourport->dma || !ourport->dma->tx_chan)
                        s3c24xx_serial_start_tx_pio(ourport);
        }
@@ -494,14 +494,14 @@ static void s3c24xx_serial_stop_rx(struct uart_port *port)
        enum dma_status dma_status;
        unsigned int received;
 
-       if (rx_enabled(port)) {
+       if (ourport->rx_enabled) {
                dev_dbg(port->dev, "stopping rx\n");
                if (s3c24xx_serial_has_interrupt_mask(port))
                        s3c24xx_set_bit(port, S3C64XX_UINTM_RXD,
                                        S3C64XX_UINTM);
                else
                        disable_irq_nosync(ourport->rx_irq);
-               rx_enabled(port) = 0;
+               ourport->rx_enabled = 0;
        }
        if (dma && dma->rx_chan) {
                dmaengine_pause(dma->tx_chan);
@@ -723,9 +723,9 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
                if (port->flags & UPF_CONS_FLOW) {
                        int txe = s3c24xx_serial_txempty_nofifo(port);
 
-                       if (rx_enabled(port)) {
+                       if (ourport->rx_enabled) {
                                if (!txe) {
-                                       rx_enabled(port) = 0;
+                                       ourport->rx_enabled = 0;
                                        continue;
                                }
                        } else {
@@ -733,7 +733,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
                                        ufcon = rd_regl(port, S3C2410_UFCON);
                                        ufcon |= S3C2410_UFCON_RESETRX;
                                        wr_regl(port, S3C2410_UFCON, ufcon);
-                                       rx_enabled(port) = 1;
+                                       ourport->rx_enabled = 1;
                                        return;
                                }
                                continue;
@@ -1084,7 +1084,7 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
        if (ourport->tx_claimed) {
                if (!s3c24xx_serial_has_interrupt_mask(port))
                        free_irq(ourport->tx_irq, ourport);
-               tx_enabled(port) = 0;
+               ourport->tx_enabled = 0;
                ourport->tx_claimed = 0;
                ourport->tx_mode = 0;
        }
@@ -1093,7 +1093,7 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
                if (!s3c24xx_serial_has_interrupt_mask(port))
                        free_irq(ourport->rx_irq, ourport);
                ourport->rx_claimed = 0;
-               rx_enabled(port) = 0;
+               ourport->rx_enabled = 0;
        }
 
        /* Clear pending interrupts and mask all interrupts */
@@ -1115,7 +1115,7 @@ static int s3c24xx_serial_startup(struct uart_port *port)
        struct s3c24xx_uart_port *ourport = to_ourport(port);
        int ret;
 
-       rx_enabled(port) = 1;
+       ourport->rx_enabled = 1;
 
        ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0,
                          s3c24xx_serial_portname(port), ourport);
@@ -1129,7 +1129,7 @@ static int s3c24xx_serial_startup(struct uart_port *port)
 
        dev_dbg(port->dev, "requesting tx irq...\n");
 
-       tx_enabled(port) = 1;
+       ourport->tx_enabled = 1;
 
        ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0,
                          s3c24xx_serial_portname(port), ourport);
@@ -1176,9 +1176,9 @@ static int s3c64xx_serial_startup(struct uart_port *port)
        }
 
        /* For compatibility with s3c24xx Soc's */
-       rx_enabled(port) = 1;
+       ourport->rx_enabled = 1;
        ourport->rx_claimed = 1;
-       tx_enabled(port) = 0;
+       ourport->tx_enabled = 0;
        ourport->tx_claimed = 1;
 
        spin_lock_irqsave(&port->lock, flags);
@@ -2112,9 +2112,9 @@ static int s3c24xx_serial_resume_noirq(struct device *dev)
                if (s3c24xx_serial_has_interrupt_mask(port)) {
                        unsigned int uintm = 0xf;
 
-                       if (tx_enabled(port))
+                       if (ourport->tx_enabled)
                                uintm &= ~S3C64XX_UINTM_TXD_MSK;
-                       if (rx_enabled(port))
+                       if (ourport->rx_enabled)
                                uintm &= ~S3C64XX_UINTM_RXD_MSK;
                        clk_prepare_enable(ourport->clk);
                        if (!IS_ERR(ourport->baudclk))