Skip to content

Commit b320441

Browse files
committed
Merge tag 'tty-6.5-rc7' 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 core fixes for 6.5-rc7 that resolve a lot of reported issues. Primarily in here are the fixes for the serial bus code from Tony that came in -rc1, as it hit wider testing with the huge number of different types of systems and serial ports. All of the reported issues with duplicate names and other issues with this code are now resolved. Other than that included in here is: - n_gsm fix for a previous fix - 8250 lockdep annotation fix - fsl_lpuart serial driver fix - TIOCSTI documentation update for previous CAP_SYS_ADMIN change All of these have been in linux-next for a while with no reported problems" * tag 'tty-6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: serial: core: Fix serial core port id, including multiport devices serial: 8250: drop lockdep annotation from serial8250_clear_IER() tty: n_gsm: fix the UAF caused by race condition in gsm_cleanup_mux serial: core: Revert port_id use TIOCSTI: Document CAP_SYS_ADMIN behaviour in Kconfig serial: 8250: Fix oops for port->pm on uart_change_pm() serial: 8250: Reinit port_id when adding back serial8250_isa_devs serial: core: Fix kmemleak issue for serial core device remove MAINTAINERS: Merge TTY layer and serial drivers serial: core: Fix serial_base_match() after fixing controller port name serial: core: Fix serial core controller port name to show controller id serial: core: Fix serial core port id to not use port->line serial: core: Controller id cannot be negative tty: serial: fsl_lpuart: Clear the error flags by writing 1 for lpuart32 platforms
2 parents ec27a63 + 04c7f60 commit b320441

File tree

9 files changed

+72
-34
lines changed

9 files changed

+72
-34
lines changed

MAINTAINERS

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19224,13 +19224,6 @@ F: Documentation/devicetree/bindings/serial/serial.yaml
1922419224
F: drivers/tty/serdev/
1922519225
F: include/linux/serdev.h
1922619226

19227-
SERIAL DRIVERS
19228-
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19229-
L: linux-serial@vger.kernel.org
19230-
S: Maintained
19231-
F: Documentation/devicetree/bindings/serial/
19232-
F: drivers/tty/serial/
19233-
1923419227
SERIAL IR RECEIVER
1923519228
M: Sean Young <sean@mess.org>
1923619229
L: linux-media@vger.kernel.org
@@ -21635,20 +21628,16 @@ W: https://github.com/srcres258/linux-doc
2163521628
T: git git://github.com/srcres258/linux-doc.git doc-zh-tw
2163621629
F: Documentation/translations/zh_TW/
2163721630

21638-
TTY LAYER
21631+
TTY LAYER AND SERIAL DRIVERS
2163921632
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2164021633
M: Jiri Slaby <jirislaby@kernel.org>
2164121634
L: linux-kernel@vger.kernel.org
2164221635
L: linux-serial@vger.kernel.org
2164321636
S: Supported
2164421637
T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
21638+
F: Documentation/devicetree/bindings/serial/
2164521639
F: Documentation/driver-api/serial/
2164621640
F: drivers/tty/
21647-
F: drivers/tty/serial/serial_base.h
21648-
F: drivers/tty/serial/serial_base_bus.c
21649-
F: drivers/tty/serial/serial_core.c
21650-
F: drivers/tty/serial/serial_ctrl.c
21651-
F: drivers/tty/serial/serial_port.c
2165221641
F: include/linux/selection.h
2165321642
F: include/linux/serial.h
2165421643
F: include/linux/serial_core.h

drivers/tty/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ config LEGACY_TIOCSTI
164164
userspace depends on this functionality to continue operating
165165
normally.
166166

167+
Processes which run with CAP_SYS_ADMIN, such as BRLTTY, can
168+
use TIOCSTI even when this is set to N.
169+
167170
This functionality can be changed at runtime with the
168171
dev.tty.legacy_tiocsti sysctl. This configuration option sets
169172
the default value of the sysctl.

drivers/tty/n_gsm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,12 +3042,13 @@ static void gsm_error(struct gsm_mux *gsm)
30423042
static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
30433043
{
30443044
int i;
3045-
struct gsm_dlci *dlci = gsm->dlci[0];
3045+
struct gsm_dlci *dlci;
30463046
struct gsm_msg *txq, *ntxq;
30473047

30483048
gsm->dead = true;
30493049
mutex_lock(&gsm->mutex);
30503050

3051+
dlci = gsm->dlci[0];
30513052
if (dlci) {
30523053
if (disc && dlci->state != DLCI_CLOSED) {
30533054
gsm_dlci_begin_close(dlci);

drivers/tty/serial/8250/8250_core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ static struct uart_8250_port *serial8250_setup_port(int index)
497497

498498
up = &serial8250_ports[index];
499499
up->port.line = index;
500+
up->port.port_id = index;
500501

501502
serial8250_init_port(up);
502503
if (!base_ops)
@@ -1040,6 +1041,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
10401041
uart_remove_one_port(&serial8250_reg, &uart->port);
10411042

10421043
uart->port.ctrl_id = up->port.ctrl_id;
1044+
uart->port.port_id = up->port.port_id;
10431045
uart->port.iobase = up->port.iobase;
10441046
uart->port.membase = up->port.membase;
10451047
uart->port.irq = up->port.irq;
@@ -1202,6 +1204,7 @@ void serial8250_unregister_port(int line)
12021204
uart->port.flags &= ~UPF_BOOT_AUTOCONF;
12031205
uart->port.type = PORT_UNKNOWN;
12041206
uart->port.dev = &serial8250_isa_devs->dev;
1207+
uart->port.port_id = line;
12051208
uart->capabilities = 0;
12061209
serial8250_init_port(uart);
12071210
serial8250_apply_quirks(uart);

drivers/tty/serial/8250/8250_port.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,6 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
703703

704704
static void serial8250_clear_IER(struct uart_8250_port *up)
705705
{
706-
/* Port locked to synchronize UART_IER access against the console. */
707-
lockdep_assert_held_once(&up->port.lock);
708-
709706
if (up->capabilities & UART_CAP_UUE)
710707
serial_out(up, UART_IER, UART_IER_UUE);
711708
else
@@ -3278,6 +3275,7 @@ void serial8250_init_port(struct uart_8250_port *up)
32783275

32793276
spin_lock_init(&port->lock);
32803277
port->ctrl_id = 0;
3278+
port->pm = NULL;
32813279
port->ops = &serial8250_pops;
32823280
port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
32833281

drivers/tty/serial/fsl_lpuart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
11391139
unsigned long sr = lpuart32_read(&sport->port, UARTSTAT);
11401140

11411141
if (sr & (UARTSTAT_PE | UARTSTAT_FE)) {
1142-
/* Read DR to clear the error flags */
1143-
lpuart32_read(&sport->port, UARTDATA);
1142+
/* Clear the error flags */
1143+
lpuart32_write(&sport->port, sr, UARTSTAT);
11441144

11451145
if (sr & UARTSTAT_PE)
11461146
sport->port.icount.parity++;

drivers/tty/serial/serial_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct device;
1616

1717
struct serial_ctrl_device {
1818
struct device dev;
19+
struct ida port_ida;
1920
};
2021

2122
struct serial_port_device {

drivers/tty/serial/serial_base_bus.c

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/container_of.h>
1212
#include <linux/device.h>
13+
#include <linux/idr.h>
1314
#include <linux/module.h>
1415
#include <linux/serial_core.h>
1516
#include <linux/slab.h>
@@ -19,11 +20,25 @@
1920

2021
static bool serial_base_initialized;
2122

23+
static const struct device_type serial_ctrl_type = {
24+
.name = "ctrl",
25+
};
26+
27+
static const struct device_type serial_port_type = {
28+
.name = "port",
29+
};
30+
2231
static int serial_base_match(struct device *dev, struct device_driver *drv)
2332
{
24-
int len = strlen(drv->name);
33+
if (dev->type == &serial_ctrl_type &&
34+
str_has_prefix(drv->name, serial_ctrl_type.name))
35+
return 1;
2536

26-
return !strncmp(dev_name(dev), drv->name, len);
37+
if (dev->type == &serial_port_type &&
38+
str_has_prefix(drv->name, serial_port_type.name))
39+
return 1;
40+
41+
return 0;
2742
}
2843

2944
static struct bus_type serial_base_bus_type = {
@@ -48,7 +63,8 @@ static int serial_base_device_init(struct uart_port *port,
4863
struct device *parent_dev,
4964
const struct device_type *type,
5065
void (*release)(struct device *dev),
51-
int id)
66+
unsigned int ctrl_id,
67+
unsigned int port_id)
5268
{
5369
device_initialize(dev);
5470
dev->type = type;
@@ -61,12 +77,15 @@ static int serial_base_device_init(struct uart_port *port,
6177
return -EPROBE_DEFER;
6278
}
6379

64-
return dev_set_name(dev, "%s.%s.%d", type->name, dev_name(port->dev), id);
65-
}
80+
if (type == &serial_ctrl_type)
81+
return dev_set_name(dev, "%s:%d", dev_name(port->dev), ctrl_id);
6682

67-
static const struct device_type serial_ctrl_type = {
68-
.name = "ctrl",
69-
};
83+
if (type == &serial_port_type)
84+
return dev_set_name(dev, "%s:%d.%d", dev_name(port->dev),
85+
ctrl_id, port_id);
86+
87+
return -EINVAL;
88+
}
7089

7190
static void serial_base_ctrl_release(struct device *dev)
7291
{
@@ -81,6 +100,7 @@ void serial_base_ctrl_device_remove(struct serial_ctrl_device *ctrl_dev)
81100
return;
82101

83102
device_del(&ctrl_dev->dev);
103+
put_device(&ctrl_dev->dev);
84104
}
85105

86106
struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
@@ -93,10 +113,12 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
93113
if (!ctrl_dev)
94114
return ERR_PTR(-ENOMEM);
95115

116+
ida_init(&ctrl_dev->port_ida);
117+
96118
err = serial_base_device_init(port, &ctrl_dev->dev,
97119
parent, &serial_ctrl_type,
98120
serial_base_ctrl_release,
99-
port->ctrl_id);
121+
port->ctrl_id, 0);
100122
if (err)
101123
goto err_put_device;
102124

@@ -112,10 +134,6 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
112134
return ERR_PTR(err);
113135
}
114136

115-
static const struct device_type serial_port_type = {
116-
.name = "port",
117-
};
118-
119137
static void serial_base_port_release(struct device *dev)
120138
{
121139
struct serial_port_device *port_dev = to_serial_base_port_device(dev);
@@ -127,16 +145,31 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
127145
struct serial_ctrl_device *ctrl_dev)
128146
{
129147
struct serial_port_device *port_dev;
148+
int min = 0, max = -1; /* Use -1 for max to apply IDA defaults */
130149
int err;
131150

132151
port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
133152
if (!port_dev)
134153
return ERR_PTR(-ENOMEM);
135154

155+
/* Device driver specified port_id vs automatic assignment? */
156+
if (port->port_id) {
157+
min = port->port_id;
158+
max = port->port_id;
159+
}
160+
161+
err = ida_alloc_range(&ctrl_dev->port_ida, min, max, GFP_KERNEL);
162+
if (err < 0) {
163+
kfree(port_dev);
164+
return ERR_PTR(err);
165+
}
166+
167+
port->port_id = err;
168+
136169
err = serial_base_device_init(port, &port_dev->dev,
137170
&ctrl_dev->dev, &serial_port_type,
138171
serial_base_port_release,
139-
port->line);
172+
port->ctrl_id, port->port_id);
140173
if (err)
141174
goto err_put_device;
142175

@@ -150,16 +183,25 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
150183

151184
err_put_device:
152185
put_device(&port_dev->dev);
186+
ida_free(&ctrl_dev->port_ida, port->port_id);
153187

154188
return ERR_PTR(err);
155189
}
156190

157191
void serial_base_port_device_remove(struct serial_port_device *port_dev)
158192
{
193+
struct serial_ctrl_device *ctrl_dev;
194+
struct device *parent;
195+
159196
if (!port_dev)
160197
return;
161198

199+
parent = port_dev->dev.parent;
200+
ctrl_dev = to_serial_base_ctrl_device(parent);
201+
162202
device_del(&port_dev->dev);
203+
ida_free(&ctrl_dev->port_ida, port_dev->port->port_id);
204+
put_device(&port_dev->dev);
163205
}
164206

165207
static int serial_base_init(void)

include/linux/serial_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ struct uart_port {
459459
struct serial_rs485 *rs485);
460460
int (*iso7816_config)(struct uart_port *,
461461
struct serial_iso7816 *iso7816);
462-
int ctrl_id; /* optional serial core controller id */
462+
unsigned int ctrl_id; /* optional serial core controller id */
463+
unsigned int port_id; /* optional serial core port id */
463464
unsigned int irq; /* irq number */
464465
unsigned long irqflags; /* irq flags */
465466
unsigned int uartclk; /* base uart clock */

0 commit comments

Comments
 (0)