Re: [PATCH] serial: 8250_exar: Clear buffer before shutdown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 23, 2019 at 10:36:32AM -0400, Robert Middleton wrote:
> When closing and shutting down the exar serial port, if the chip
> has not finished sending all of the data in its buffer, the
> remaining bytes will be lost.  Hold off on the shutdown until the
> bytes have all been sent.
> 
> Signed-off-by: Robert Middleton <robert.middleton@xxxxxxxxxx>
> ---
>  drivers/tty/serial/8250/8250_exar.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
> index edd6dfe055bf..f58eeb670b15 100644
> --- a/drivers/tty/serial/8250/8250_exar.c
> +++ b/drivers/tty/serial/8250/8250_exar.c
> @@ -19,6 +19,7 @@
>  #include <linux/string.h>
>  #include <linux/tty.h>
>  #include <linux/8250_pci.h>
> +#include <linux/delay.h>
>  
>  #include <asm/byteorder.h>
>  
> @@ -457,6 +458,26 @@ static irqreturn_t exar_misc_handler(int irq, void *data)
>  	return IRQ_HANDLED;
>  }
>  
> +static void
> +exar_shutdown(struct uart_port *port)
> +{
> +	unsigned char lsr;
> +	bool tx_complete = 0;
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	struct circ_buf *xmit = &port->state->xmit;
> +
> +	do {
> +		lsr = serial_in(up, UART_LSR);
> +		if (lsr & (UART_LSR_TEMT | UART_LSR_THRE))
> +			tx_complete = 1;
> +		else
> +			tx_complete = 0;
> +		msleep(1);
> +	} while (!uart_circ_empty(xmit) && !tx_complete);

What if the hardware is locked up?  Will this sit and spin forever?
Shouldn't you also have a timeout for the flush?

thanks,

greg k-h



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux