serial: core: Fix serial_base_match() after fixing controller port name
PATCH 1/1 serial: core: Fix serial_base_match() after fixing controller port name
While fixing DEVNAME to be more usable, I broke serial_base_match() as the ctrl and port prefix for device seemed unnecessary.
Let's fix the issue by checking against dev->type and drv->name.
--- drivers/tty/serial/serial_base.h | 3 +++ drivers/tty/serial/serial_base_bus.c | 10 ++++++++-- drivers/tty/serial/serial_ctrl.c | 2 +- drivers/tty/serial/serial_port.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-)
drivers/tty/serial/serial_base.h +3 -0
@@ -6,6 +6,9 @@* Author: Tony Lindgren <[email protected]> */ +#define SERIAL_BASE_CTRL_NAME "ctrl" +#define SERIAL_BASE_PORT_NAME "port" +#define to_serial_base_ctrl_device (d) container_of((d), struct serial_ctrl_device, dev)#define to_serial_base_port_device (d) container_of((d), struct serial_port_device, dev)
drivers/tty/serial/serial_base_bus.c +8 -2
@@ -29,9 +29,15 @@ static const struct device_type serial_port_type = {static int serial_base_match (struct device *dev,struct device_driver *drv) { -int len =strlen (drv->name); +if (dev->type == &serial_ctrl_type && + !strncmp (SERIAL_BASE_CTRL_NAME , drv->name,4 )) +return 1 ; -return !strncmp (dev_name (dev), drv->name, len); +if (dev->type == &serial_port_type && + !strncmp (SERIAL_BASE_PORT_NAME , drv->name,4 )) +return 1 ; + +return 0 ; }static struct bus_type serial_base_bus_type = {
drivers/tty/serial/serial_ctrl.c +1 -1
@@ -47,7 +47,7 @@ void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port }static struct device_driver serial_ctrl_driver = { - .name ="ctrl" , + .name =SERIAL_BASE_CTRL_NAME , .suppress_bind_attrs = true, .probe = serial_ctrl_probe, .remove = serial_ctrl_remove,
drivers/tty/serial/serial_port.c +1 -1
@@ -83,7 +83,7 @@ void uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)EXPORT_SYMBOL (uart_remove_one_port);static struct device_driver serial_port_driver = { - .name ="port" , + .name =SERIAL_BASE_PORT_NAME , .suppress_bind_attrs = true, .probe = serial_port_probe, .remove = serial_port_remove,
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerQuoted 32 lines · Tony Lindgren
While fixing DEVNAME to be more usable, I broke
serial_base_match()as the ctrl and port prefix for device seemed unnecessary.Let's fix the issue by checking against
dev->typeanddrv->name.Fixes 1ef2c2df1199 ("serial: core: Fix serial core controller port name to show controller id")Reported-by kernel test robot <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/tty/serial/serial_base.h | 3 +++ drivers/tty/serial/serial_base_bus.c | 10 ++++++++-- drivers/tty/serial/serial_ctrl.c | 2 +- drivers/tty/serial/serial_port.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-)drivers/tty/serial/serial_base.h +3
-0@@ -6,6 +6,9 @@* Author: Tony Lindgren <[email protected]> */ +#define SERIAL_BASE_CTRL_NAME "ctrl" +#define SERIAL_BASE_PORT_NAME "port" +#define to_serial_base_ctrl_device (d) container_of((d), struct serial_ctrl_device, dev)#define to_serial_base_port_device (d) container_of((d), struct serial_port_device, dev)
drivers/tty/serial/serial_base_bus.c static const struct device_type serial_port_type = { · line 33
Quoted 6 lines
drivers/tty/serial/serial_base_bus.c +2
-1@@ -29,9 +29,15 @@ static const struct device_type serial_port_type = {static int serial_base_match (struct device *dev,struct device_driver *drv) { -int len =strlen (drv->name); +if (dev->type == &serial_ctrl_type && + !strncmp (SERIAL_BASE_CTRL_NAME , drv->name,4 ))
maybe:
!strncmp(SERIAL_BASE_CTRL_NAME, drv->name, strlen(SERIAL_BASE_CTRL_NAME))
as "4" is a magic number :)
thanks,
greg k-h
Quoted 4 lines · Tony Lindgren
While fixing DEVNAME to be more usable, I broke
serial_base_match()as the ctrl and port prefix for device seemed unnecessary.Let's fix the issue by checking against
dev->typeanddrv->name.
This fixes boot on at least i.MX8MP-EVK:
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Tony Lindgren
While fixing DEVNAME to be more usable, I broke
serial_base_match()as the ctrl and port prefix for device seemed unnecessary.Let's fix the issue by checking against
dev->typeanddrv->name.
...
Quoted 6 lines
drivers/tty/serial/serial_base_bus.c static const struct device_type serial_port_type = { · line 33
Quoted 1 line
drivers/tty/serial/serial_base_bus.c +1
-0+ !strncmp(SERIAL_BASE_CTRL_NAME, drv->name, 4))maybe:
!strncmp(SERIAL_BASE_CTRL_NAME, drv->name, strlen(SERIAL_BASE_CTRL_NAME))as "4" is a magic number :)
str_has_prefix() hides that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jiri Slaby
maintainerQuoted 2 lines · Tony Lindgren
While fixing DEVNAME to be more usable, I broke
serial_base_match()as the ctrl and port prefix for device seemed unnecessary.
It's not completely clear to me what you are actually fixing. Please elaborate in more detail.
Quoted 6 lines
Let's fix the issue by checking against
dev->typeanddrv->name.Fixes 1ef2c2df1199 ("serial: core: Fix serial core controller port name to show controller id")Reported-by kernel test robot <[email protected]>
Then we are missing a Link here.
Quoted 12 lines
Signed-off-by Tony Lindgren <[email protected]>--- drivers/tty/serial/serial_base.h | 3 +++ drivers/tty/serial/serial_base_bus.c | 10 ++++++++-- drivers/tty/serial/serial_ctrl.c | 2 +- drivers/tty/serial/serial_port.c | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-)
drivers/tty/serial/serial_base.h line 10
Quoted 5 lines
drivers/tty/serial/serial_base.h +2
-0@@ -6,6 +6,9 @@* Author: Tony Lindgren <[email protected]> */ +#define SERIAL_BASE_CTRL_NAME "ctrl" +#define SERIAL_BASE_PORT_NAME "port"
Could you make those char[] instead? The compiler/linker will hopefully (will it?) de-dup the occurrences, but the arrays would look cleaner and safer from this POV.
Quoted 48 lines
drivers/tty/serial/serial_base.h +0
-0#define to_serial_base_ctrl_device (d) container_of((d), struct serial_ctrl_device, dev)#define to_serial_base_port_device (d) container_of((d), struct serial_port_device, dev)drivers/tty/serial/serial_base_bus.c +8
-2@@ -29,9 +29,15 @@ static const struct device_type serial_port_type = {static int serial_base_match (struct device *dev,struct device_driver *drv) { -int len =strlen (drv->name); +if (dev->type == &serial_ctrl_type && + !strncmp (SERIAL_BASE_CTRL_NAME , drv->name,4 )) +return 1 ; -return !strncmp (dev_name (dev), drv->name, len); +if (dev->type == &serial_port_type && + !strncmp (SERIAL_BASE_PORT_NAME , drv->name,4 )) +return 1 ; + +return 0 ; }static struct bus_type serial_base_bus_type = {drivers/tty/serial/serial_ctrl.c +1
-1@@ -47,7 +47,7 @@ void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port }static struct device_driver serial_ctrl_driver = { - .name ="ctrl" , + .name =SERIAL_BASE_CTRL_NAME , .suppress_bind_attrs = true, .probe = serial_ctrl_probe, .remove = serial_ctrl_remove,drivers/tty/serial/serial_port.c +1
-1@@ -83,7 +83,7 @@ void uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)EXPORT_SYMBOL (uart_remove_one_port);static struct device_driver serial_port_driver = { - .name ="port" , + .name =SERIAL_BASE_PORT_NAME , .suppress_bind_attrs = true, .probe = serial_port_probe, .remove = serial_port_remove,
Signature · 2 lines
js suse labs
Quoted 10 lines · Jiri Slaby
drivers/tty/serial/serial_base.h line 9
Quoted 5 lines · Tony Lindgren
drivers/tty/serial/serial_base.h +2
-0@@ -6,6 +6,9 @@* Author: Tony Lindgren <[email protected]> */ +#define SERIAL_BASE_CTRL_NAME "ctrl" +#define SERIAL_BASE_PORT_NAME "port"Could you make those char[] instead? The compiler/linker will hopefully (will it?) de-dup the occurrences, but the arrays would look cleaner and safer from this POV.
Heh yeah so we already have that in serial_ctrl_type.name and serial_port_type.name so let's just check against those for a minimal fix.
Regards,
Tony
Quoted 8 lines · Tony Lindgren
While fixing DEVNAME to be more usable, I broke
serial_base_match()as the ctrl and port prefix for device seemed unnecessary.Let's fix the issue by checking against
dev->typeanddrv->name.Fixes 1ef2c2df1199 ("serial: core: Fix serial core controller port name to show controller id")Reported-by kernel test robot <[email protected]>Signed-off-by Tony Lindgren <[email protected]>
This fixes boot on e850-96.