Skip to content

Commit 0214960

Browse files
committed
Merge tag 'tty-6.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty and serial driver fixes from Greg KH: "Here are some small tty and serial driver fixes for 6.8-rc3 that resolve a number of reported issues. Included in here are: - rs485 flag definition fix that affected the user/kernel abi in -rc1 - max310x driver fixes - 8250_pci1xxxx driver off-by-one fix - uart_tiocmget locking race fix All of these have been in linux-next for over a week with no reported issues" * tag 'tty-6.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: serial: max310x: prevent infinite while() loop in port startup serial: max310x: fail probe if clock crystal is unstable serial: max310x: improve crystal stable clock detection serial: max310x: set default value when reading clock ready bit serial: core: Fix atomicity violation in uart_tiocmget serial: 8250_pci1xxxx: fix off by one in pci1xxxx_process_read_data() tty: serial: Fix bit order in RS485 flag definitions
2 parents 809be62 + b35f8db commit 0214960

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

drivers/tty/serial/8250/8250_pci1xxxx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
302302
* to read, the data is received one byte at a time.
303303
*/
304304
while (valid_burst_count--) {
305-
if (*buff_index > (RX_BUF_SIZE - UART_BURST_SIZE))
305+
if (*buff_index >= (RX_BUF_SIZE - UART_BURST_SIZE))
306306
break;
307307
burst_buf = (u32 *)&rx_buff[*buff_index];
308308
*burst_buf = readl(port->membase + UART_RX_BURST_FIFO);
@@ -311,7 +311,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
311311
}
312312

313313
while (*valid_byte_count) {
314-
if (*buff_index > RX_BUF_SIZE)
314+
if (*buff_index >= RX_BUF_SIZE)
315315
break;
316316
rx_buff[*buff_index] = readb(port->membase +
317317
UART_RX_BYTE_FIFO);

drivers/tty/serial/max310x.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@
237237
#define MAX310x_REV_MASK (0xf8)
238238
#define MAX310X_WRITE_BIT 0x80
239239

240+
/* Port startup definitions */
241+
#define MAX310X_PORT_STARTUP_WAIT_RETRIES 20 /* Number of retries */
242+
#define MAX310X_PORT_STARTUP_WAIT_DELAY_MS 10 /* Delay between retries */
243+
244+
/* Crystal-related definitions */
245+
#define MAX310X_XTAL_WAIT_RETRIES 20 /* Number of retries */
246+
#define MAX310X_XTAL_WAIT_DELAY_MS 10 /* Delay between retries */
247+
240248
/* MAX3107 specific */
241249
#define MAX3107_REV_ID (0xa0)
242250

@@ -583,7 +591,7 @@ static int max310x_update_best_err(unsigned long f, long *besterr)
583591
return 1;
584592
}
585593

586-
static u32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
594+
static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
587595
unsigned long freq, bool xtal)
588596
{
589597
unsigned int div, clksrc, pllcfg = 0;
@@ -641,12 +649,20 @@ static u32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
641649

642650
/* Wait for crystal */
643651
if (xtal) {
644-
unsigned int val;
645-
msleep(10);
646-
regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val);
647-
if (!(val & MAX310X_STS_CLKREADY_BIT)) {
648-
dev_warn(dev, "clock is not stable yet\n");
649-
}
652+
bool stable = false;
653+
unsigned int try = 0, val = 0;
654+
655+
do {
656+
msleep(MAX310X_XTAL_WAIT_DELAY_MS);
657+
regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val);
658+
659+
if (val & MAX310X_STS_CLKREADY_BIT)
660+
stable = true;
661+
} while (!stable && (++try < MAX310X_XTAL_WAIT_RETRIES));
662+
663+
if (!stable)
664+
return dev_err_probe(dev, -EAGAIN,
665+
"clock is not stable\n");
650666
}
651667

652668
return bestfreq;
@@ -1271,7 +1287,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
12711287
{
12721288
int i, ret, fmin, fmax, freq;
12731289
struct max310x_port *s;
1274-
u32 uartclk = 0;
1290+
s32 uartclk = 0;
12751291
bool xtal;
12761292

12771293
for (i = 0; i < devtype->nr; i++)
@@ -1334,6 +1350,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
13341350
goto out_clk;
13351351

13361352
for (i = 0; i < devtype->nr; i++) {
1353+
bool started = false;
1354+
unsigned int try = 0, val = 0;
1355+
13371356
/* Reset port */
13381357
regmap_write(regmaps[i], MAX310X_MODE2_REG,
13391358
MAX310X_MODE2_RST_BIT);
@@ -1342,13 +1361,27 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
13421361

13431362
/* Wait for port startup */
13441363
do {
1345-
regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &ret);
1346-
} while (ret != 0x01);
1364+
msleep(MAX310X_PORT_STARTUP_WAIT_DELAY_MS);
1365+
regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &val);
1366+
1367+
if (val == 0x01)
1368+
started = true;
1369+
} while (!started && (++try < MAX310X_PORT_STARTUP_WAIT_RETRIES));
1370+
1371+
if (!started) {
1372+
ret = dev_err_probe(dev, -EAGAIN, "port reset failed\n");
1373+
goto out_uart;
1374+
}
13471375

13481376
regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1);
13491377
}
13501378

13511379
uartclk = max310x_set_ref_clk(dev, s, freq, xtal);
1380+
if (uartclk < 0) {
1381+
ret = uartclk;
1382+
goto out_uart;
1383+
}
1384+
13521385
dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk);
13531386

13541387
for (i = 0; i < devtype->nr; i++) {

drivers/tty/serial/serial_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ static int uart_tiocmget(struct tty_struct *tty)
10841084
goto out;
10851085

10861086
if (!tty_io_error(tty)) {
1087-
result = uport->mctrl;
10881087
uart_port_lock_irq(uport);
1088+
result = uport->mctrl;
10891089
result |= uport->ops->get_mctrl(uport);
10901090
uart_port_unlock_irq(uport);
10911091
}

include/uapi/linux/serial.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ struct serial_rs485 {
145145
#define SER_RS485_ENABLED _BITUL(0)
146146
#define SER_RS485_RTS_ON_SEND _BITUL(1)
147147
#define SER_RS485_RTS_AFTER_SEND _BITUL(2)
148-
#define SER_RS485_RX_DURING_TX _BITUL(3)
149-
#define SER_RS485_TERMINATE_BUS _BITUL(4)
150-
#define SER_RS485_ADDRB _BITUL(5)
151-
#define SER_RS485_ADDR_RECV _BITUL(6)
152-
#define SER_RS485_ADDR_DEST _BITUL(7)
153-
#define SER_RS485_MODE_RS422 _BITUL(8)
148+
/* Placeholder for bit 3: SER_RS485_RTS_BEFORE_SEND, which isn't used anymore */
149+
#define SER_RS485_RX_DURING_TX _BITUL(4)
150+
#define SER_RS485_TERMINATE_BUS _BITUL(5)
151+
#define SER_RS485_ADDRB _BITUL(6)
152+
#define SER_RS485_ADDR_RECV _BITUL(7)
153+
#define SER_RS485_ADDR_DEST _BITUL(8)
154+
#define SER_RS485_MODE_RS422 _BITUL(9)
154155

155156
__u32 delay_rts_before_send;
156157
__u32 delay_rts_after_send;

0 commit comments

Comments
 (0)