Skip to content

Commit 52afe19

Browse files
committed
Merge tag 'tty-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial fixes from Greg KH: "Here are some small tty and serial driver fixes for 5.1-rc3. Nothing major here, just a number of potential problems fixes for error handling paths, as well as some other minor bugfixes for reported issues with 5.1-rc1. All of these have been in linux-next with no reported issues" * tag 'tty-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: tty: fix NULL pointer issue when tty_port ops is not set Disable kgdboc failed by echo space to /sys/module/kgdboc/parameters/kgdboc dt-bindings: serial: Add compatible for Mediatek MT8183 tty/serial: atmel: RS485 HD w/DMA: enable RX after TX is stopped tty/serial: atmel: Add is_half_duplex helper serial: sh-sci: Fix setting SCSCR_TIE while transferring data serial: ar933x_uart: Fix build failure with disabled console tty: serial: qcom_geni_serial: Initialize baud in qcom_geni_console_setup sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() tty: mxs-auart: fix a potential NULL pointer dereference tty: atmel_serial: fix a potential NULL pointer dereference serial: max310x: Fix to avoid potential NULL pointer dereference serial: mvebu-uart: Fix to avoid a potential NULL pointer dereference
2 parents 8d02a9a + f4e68d5 commit 52afe19

File tree

11 files changed

+75
-51
lines changed

11 files changed

+75
-51
lines changed

Documentation/devicetree/bindings/serial/mtk-uart.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Required properties:
1616
* "mediatek,mt8127-uart" for MT8127 compatible UARTS
1717
* "mediatek,mt8135-uart" for MT8135 compatible UARTS
1818
* "mediatek,mt8173-uart" for MT8173 compatible UARTS
19+
* "mediatek,mt8183-uart", "mediatek,mt6577-uart" for MT8183 compatible UARTS
1920
* "mediatek,mt6577-uart" for MT6577 and all of the above
2021

2122
- reg: The base address of the UART register bank.

drivers/tty/serial/ar933x_uart.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ struct ar933x_uart_port {
4949
struct clk *clk;
5050
};
5151

52-
static inline bool ar933x_uart_console_enabled(void)
53-
{
54-
return IS_ENABLED(CONFIG_SERIAL_AR933X_CONSOLE);
55-
}
56-
5752
static inline unsigned int ar933x_uart_read(struct ar933x_uart_port *up,
5853
int offset)
5954
{
@@ -508,6 +503,7 @@ static const struct uart_ops ar933x_uart_ops = {
508503
.verify_port = ar933x_uart_verify_port,
509504
};
510505

506+
#ifdef CONFIG_SERIAL_AR933X_CONSOLE
511507
static struct ar933x_uart_port *
512508
ar933x_console_ports[CONFIG_SERIAL_AR933X_NR_UARTS];
513509

@@ -604,14 +600,7 @@ static struct console ar933x_uart_console = {
604600
.index = -1,
605601
.data = &ar933x_uart_driver,
606602
};
607-
608-
static void ar933x_uart_add_console_port(struct ar933x_uart_port *up)
609-
{
610-
if (!ar933x_uart_console_enabled())
611-
return;
612-
613-
ar933x_console_ports[up->port.line] = up;
614-
}
603+
#endif /* CONFIG_SERIAL_AR933X_CONSOLE */
615604

616605
static struct uart_driver ar933x_uart_driver = {
617606
.owner = THIS_MODULE,
@@ -700,7 +689,9 @@ static int ar933x_uart_probe(struct platform_device *pdev)
700689
baud = ar933x_uart_get_baud(port->uartclk, 0, AR933X_UART_MAX_STEP);
701690
up->max_baud = min_t(unsigned int, baud, AR933X_UART_MAX_BAUD);
702691

703-
ar933x_uart_add_console_port(up);
692+
#ifdef CONFIG_SERIAL_AR933X_CONSOLE
693+
ar933x_console_ports[up->port.line] = up;
694+
#endif
704695

705696
ret = uart_add_one_port(&ar933x_uart_driver, &up->port);
706697
if (ret)
@@ -749,8 +740,9 @@ static int __init ar933x_uart_init(void)
749740
{
750741
int ret;
751742

752-
if (ar933x_uart_console_enabled())
753-
ar933x_uart_driver.cons = &ar933x_uart_console;
743+
#ifdef CONFIG_SERIAL_AR933X_CONSOLE
744+
ar933x_uart_driver.cons = &ar933x_uart_console;
745+
#endif
754746

755747
ret = uart_register_driver(&ar933x_uart_driver);
756748
if (ret)

drivers/tty/serial/atmel_serial.c

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ struct atmel_uart_port {
166166
unsigned int pending_status;
167167
spinlock_t lock_suspended;
168168

169+
bool hd_start_rx; /* can start RX during half-duplex operation */
170+
169171
/* ISO7816 */
170172
unsigned int fidi_min;
171173
unsigned int fidi_max;
@@ -231,6 +233,13 @@ static inline void atmel_uart_write_char(struct uart_port *port, u8 value)
231233
__raw_writeb(value, port->membase + ATMEL_US_THR);
232234
}
233235

236+
static inline int atmel_uart_is_half_duplex(struct uart_port *port)
237+
{
238+
return ((port->rs485.flags & SER_RS485_ENABLED) &&
239+
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) ||
240+
(port->iso7816.flags & SER_ISO7816_ENABLED);
241+
}
242+
234243
#ifdef CONFIG_SERIAL_ATMEL_PDC
235244
static bool atmel_use_pdc_rx(struct uart_port *port)
236245
{
@@ -608,10 +617,9 @@ static void atmel_stop_tx(struct uart_port *port)
608617
/* Disable interrupts */
609618
atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask);
610619

611-
if (((port->rs485.flags & SER_RS485_ENABLED) &&
612-
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) ||
613-
port->iso7816.flags & SER_ISO7816_ENABLED)
620+
if (atmel_uart_is_half_duplex(port))
614621
atmel_start_rx(port);
622+
615623
}
616624

617625
/*
@@ -628,9 +636,7 @@ static void atmel_start_tx(struct uart_port *port)
628636
return;
629637

630638
if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port))
631-
if (((port->rs485.flags & SER_RS485_ENABLED) &&
632-
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) ||
633-
port->iso7816.flags & SER_ISO7816_ENABLED)
639+
if (atmel_uart_is_half_duplex(port))
634640
atmel_stop_rx(port);
635641

636642
if (atmel_use_pdc_tx(port))
@@ -928,11 +934,14 @@ static void atmel_complete_tx_dma(void *arg)
928934
*/
929935
if (!uart_circ_empty(xmit))
930936
atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx);
931-
else if (((port->rs485.flags & SER_RS485_ENABLED) &&
932-
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) ||
933-
port->iso7816.flags & SER_ISO7816_ENABLED) {
934-
/* DMA done, stop TX, start RX for RS485 */
935-
atmel_start_rx(port);
937+
else if (atmel_uart_is_half_duplex(port)) {
938+
/*
939+
* DMA done, re-enable TXEMPTY and signal that we can stop
940+
* TX and start RX for RS485
941+
*/
942+
atmel_port->hd_start_rx = true;
943+
atmel_uart_writel(port, ATMEL_US_IER,
944+
atmel_port->tx_done_mask);
936945
}
937946

938947
spin_unlock_irqrestore(&port->lock, flags);
@@ -1288,6 +1297,10 @@ static int atmel_prepare_rx_dma(struct uart_port *port)
12881297
sg_dma_len(&atmel_port->sg_rx)/2,
12891298
DMA_DEV_TO_MEM,
12901299
DMA_PREP_INTERRUPT);
1300+
if (!desc) {
1301+
dev_err(port->dev, "Preparing DMA cyclic failed\n");
1302+
goto chan_err;
1303+
}
12911304
desc->callback = atmel_complete_rx_dma;
12921305
desc->callback_param = port;
12931306
atmel_port->desc_rx = desc;
@@ -1376,9 +1389,20 @@ atmel_handle_transmit(struct uart_port *port, unsigned int pending)
13761389
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
13771390

13781391
if (pending & atmel_port->tx_done_mask) {
1379-
/* Either PDC or interrupt transmission */
13801392
atmel_uart_writel(port, ATMEL_US_IDR,
13811393
atmel_port->tx_done_mask);
1394+
1395+
/* Start RX if flag was set and FIFO is empty */
1396+
if (atmel_port->hd_start_rx) {
1397+
if (!(atmel_uart_readl(port, ATMEL_US_CSR)
1398+
& ATMEL_US_TXEMPTY))
1399+
dev_warn(port->dev, "Should start RX, but TX fifo is not empty\n");
1400+
1401+
atmel_port->hd_start_rx = false;
1402+
atmel_start_rx(port);
1403+
return;
1404+
}
1405+
13821406
atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx);
13831407
}
13841408
}
@@ -1508,9 +1532,7 @@ static void atmel_tx_pdc(struct uart_port *port)
15081532
atmel_uart_writel(port, ATMEL_US_IER,
15091533
atmel_port->tx_done_mask);
15101534
} else {
1511-
if (((port->rs485.flags & SER_RS485_ENABLED) &&
1512-
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) ||
1513-
port->iso7816.flags & SER_ISO7816_ENABLED) {
1535+
if (atmel_uart_is_half_duplex(port)) {
15141536
/* DMA done, stop TX, start RX for RS485 */
15151537
atmel_start_rx(port);
15161538
}

drivers/tty/serial/kgdboc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ static int configure_kgdboc(void)
148148
char *cptr = config;
149149
struct console *cons;
150150

151-
if (!strlen(config) || isspace(config[0]))
151+
if (!strlen(config) || isspace(config[0])) {
152+
err = 0;
152153
goto noconfig;
154+
}
153155

154156
kgdboc_io_ops.is_console = 0;
155157
kgdb_tty_driver = NULL;

drivers/tty/serial/max310x.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,8 @@ static int max310x_spi_probe(struct spi_device *spi)
14151415
if (spi->dev.of_node) {
14161416
const struct of_device_id *of_id =
14171417
of_match_device(max310x_dt_ids, &spi->dev);
1418+
if (!of_id)
1419+
return -ENODEV;
14181420

14191421
devtype = (struct max310x_devtype *)of_id->data;
14201422
} else {

drivers/tty/serial/mvebu-uart.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,9 @@ static int mvebu_uart_probe(struct platform_device *pdev)
810810
return -EINVAL;
811811
}
812812

813+
if (!match)
814+
return -ENODEV;
815+
813816
/* Assume that all UART ports have a DT alias or none has */
814817
id = of_alias_get_id(pdev->dev.of_node, "serial");
815818
if (!pdev->dev.of_node || id < 0)

drivers/tty/serial/mxs-auart.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,10 @@ static int mxs_auart_probe(struct platform_device *pdev)
16861686

16871687
s->port.mapbase = r->start;
16881688
s->port.membase = ioremap(r->start, resource_size(r));
1689+
if (!s->port.membase) {
1690+
ret = -ENOMEM;
1691+
goto out_disable_clks;
1692+
}
16891693
s->port.ops = &mxs_auart_ops;
16901694
s->port.iotype = UPIO_MEM;
16911695
s->port.fifosize = MXS_AUART_FIFO_SIZE;

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ static int __init qcom_geni_console_setup(struct console *co, char *options)
10501050
{
10511051
struct uart_port *uport;
10521052
struct qcom_geni_serial_port *port;
1053-
int baud;
1053+
int baud = 9600;
10541054
int bits = 8;
10551055
int parity = 'n';
10561056
int flow = 'n';

drivers/tty/serial/sc16is7xx.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,18 +1507,26 @@ static int __init sc16is7xx_init(void)
15071507
ret = i2c_add_driver(&sc16is7xx_i2c_uart_driver);
15081508
if (ret < 0) {
15091509
pr_err("failed to init sc16is7xx i2c --> %d\n", ret);
1510-
return ret;
1510+
goto err_i2c;
15111511
}
15121512
#endif
15131513

15141514
#ifdef CONFIG_SERIAL_SC16IS7XX_SPI
15151515
ret = spi_register_driver(&sc16is7xx_spi_uart_driver);
15161516
if (ret < 0) {
15171517
pr_err("failed to init sc16is7xx spi --> %d\n", ret);
1518-
return ret;
1518+
goto err_spi;
15191519
}
15201520
#endif
15211521
return ret;
1522+
1523+
err_spi:
1524+
#ifdef CONFIG_SERIAL_SC16IS7XX_I2C
1525+
i2c_del_driver(&sc16is7xx_i2c_uart_driver);
1526+
#endif
1527+
err_i2c:
1528+
uart_unregister_driver(&sc16is7xx_uart);
1529+
return ret;
15221530
}
15231531
module_init(sc16is7xx_init);
15241532

drivers/tty/serial/sh-sci.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -838,19 +838,9 @@ static void sci_transmit_chars(struct uart_port *port)
838838

839839
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
840840
uart_write_wakeup(port);
841-
if (uart_circ_empty(xmit)) {
841+
if (uart_circ_empty(xmit))
842842
sci_stop_tx(port);
843-
} else {
844-
ctrl = serial_port_in(port, SCSCR);
845-
846-
if (port->type != PORT_SCI) {
847-
serial_port_in(port, SCxSR); /* Dummy read */
848-
sci_clear_SCxSR(port, SCxSR_TDxE_CLEAR(port));
849-
}
850843

851-
ctrl |= SCSCR_TIE;
852-
serial_port_out(port, SCSCR, ctrl);
853-
}
854844
}
855845

856846
/* On SH3, SCIF may read end-of-break as a space->mark char */

drivers/tty/tty_port.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
325325
if (tty && C_HUPCL(tty))
326326
tty_port_lower_dtr_rts(port);
327327

328-
if (port->ops->shutdown)
328+
if (port->ops && port->ops->shutdown)
329329
port->ops->shutdown(port);
330330
}
331331
out:
@@ -398,7 +398,7 @@ EXPORT_SYMBOL_GPL(tty_port_tty_wakeup);
398398
*/
399399
int tty_port_carrier_raised(struct tty_port *port)
400400
{
401-
if (port->ops->carrier_raised == NULL)
401+
if (!port->ops || !port->ops->carrier_raised)
402402
return 1;
403403
return port->ops->carrier_raised(port);
404404
}
@@ -414,7 +414,7 @@ EXPORT_SYMBOL(tty_port_carrier_raised);
414414
*/
415415
void tty_port_raise_dtr_rts(struct tty_port *port)
416416
{
417-
if (port->ops->dtr_rts)
417+
if (port->ops && port->ops->dtr_rts)
418418
port->ops->dtr_rts(port, 1);
419419
}
420420
EXPORT_SYMBOL(tty_port_raise_dtr_rts);
@@ -429,7 +429,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts);
429429
*/
430430
void tty_port_lower_dtr_rts(struct tty_port *port)
431431
{
432-
if (port->ops->dtr_rts)
432+
if (port->ops && port->ops->dtr_rts)
433433
port->ops->dtr_rts(port, 0);
434434
}
435435
EXPORT_SYMBOL(tty_port_lower_dtr_rts);
@@ -684,7 +684,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
684684

685685
if (!tty_port_initialized(port)) {
686686
clear_bit(TTY_IO_ERROR, &tty->flags);
687-
if (port->ops->activate) {
687+
if (port->ops && port->ops->activate) {
688688
int retval = port->ops->activate(port, tty);
689689
if (retval) {
690690
mutex_unlock(&port->mutex);

0 commit comments

Comments
 (0)