Skip to content

Commit 1ef2c2d

Browse files
tmlindgregkh
authored andcommitted
serial: core: Fix serial core controller port name to show controller id
We are missing the serial core controller id for the serial core port name. Let's fix the issue for sane sysfs output, and to avoid issues addressing serial ports later on. And as we're now showing the controller id, the "ctrl" and "port" prefix for the DEVNAME become useless, we can just drop them. Let's standardize on DEVNAME:0 for controller name, where 0 is the controller id. And DEVNAME:0.0 for port name, where 0.0 are the controller id and port id. This makes the sysfs output nicer, on qemu for example: $ ls /sys/bus/serial-base/devices 00:04:0 serial8250:0 serial8250:0.2 00:04:0.0 serial8250:0.1 serial8250:0.3 Fixes: 84a9582 ("serial: core: Start managing serial controllers to enable runtime PM") Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20230725054216.45696-4-tony@atomide.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d962de6 commit 1ef2c2d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

drivers/tty/serial/serial_base_bus.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
static bool serial_base_initialized;
2121

22+
static const struct device_type serial_ctrl_type = {
23+
.name = "ctrl",
24+
};
25+
26+
static const struct device_type serial_port_type = {
27+
.name = "port",
28+
};
29+
2230
static int serial_base_match(struct device *dev, struct device_driver *drv)
2331
{
2432
int len = strlen(drv->name);
@@ -48,7 +56,8 @@ static int serial_base_device_init(struct uart_port *port,
4856
struct device *parent_dev,
4957
const struct device_type *type,
5058
void (*release)(struct device *dev),
51-
int id)
59+
unsigned int ctrl_id,
60+
unsigned int port_id)
5261
{
5362
device_initialize(dev);
5463
dev->type = type;
@@ -61,12 +70,15 @@ static int serial_base_device_init(struct uart_port *port,
6170
return -EPROBE_DEFER;
6271
}
6372

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

67-
static const struct device_type serial_ctrl_type = {
68-
.name = "ctrl",
69-
};
76+
if (type == &serial_port_type)
77+
return dev_set_name(dev, "%s:%d.%d", dev_name(port->dev),
78+
ctrl_id, port_id);
79+
80+
return -EINVAL;
81+
}
7082

7183
static void serial_base_ctrl_release(struct device *dev)
7284
{
@@ -96,7 +108,7 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
96108
err = serial_base_device_init(port, &ctrl_dev->dev,
97109
parent, &serial_ctrl_type,
98110
serial_base_ctrl_release,
99-
port->ctrl_id);
111+
port->ctrl_id, 0);
100112
if (err)
101113
goto err_put_device;
102114

@@ -112,10 +124,6 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
112124
return ERR_PTR(err);
113125
}
114126

115-
static const struct device_type serial_port_type = {
116-
.name = "port",
117-
};
118-
119127
static void serial_base_port_release(struct device *dev)
120128
{
121129
struct serial_port_device *port_dev = to_serial_base_port_device(dev);
@@ -136,7 +144,7 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
136144
err = serial_base_device_init(port, &port_dev->dev,
137145
&ctrl_dev->dev, &serial_port_type,
138146
serial_base_port_release,
139-
port->port_id);
147+
port->ctrl_id, port->port_id);
140148
if (err)
141149
goto err_put_device;
142150

0 commit comments

Comments
 (0)