Skip to contentSkip to conversation

serial: core: Revert port_id use

PATCH In review Tony Lindgren 3 participants 9 messages Aug 6, 2023 – Aug 10, 2023 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: core: Revert port_id use

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")
---
 drivers/tty/serial/serial_base_bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_base_bus.c +1 -1
@@ -151,7 +151,7 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 	err = serial_base_device_init(port, &port_dev->dev,
 				      &ctrl_dev->dev, &serial_port_type,
 				      serial_base_port_release,
-				      port->ctrl_id, port->port_id);
+				      port->ctrl_id, port->line);
 	if (err)
 		goto err_put_device;
 
Signature · 1 line
2.41.0
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")

Guenter

#2 lore raw

Hi,

Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Quoted 5 lines
Quoted 3 lines
Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")

Thanks for testing.

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

I'll send a proper patch assuming things test fine.

Regagrds,

Tony

8< --------------------

drivers/tty/serial/serial_base.h +1 -0
@@ -16,6 +16,7 @@ struct device;
 
 struct serial_ctrl_device {
 	struct device dev;
+	struct ida ida;
 };
 
 struct serial_port_device {
drivers/tty/serial/serial_base_bus.c +27 -1
@@ -10,6 +10,7 @@
 
 #include <linux/container_of.h>
 #include <linux/device.h>
+#include <linux/idr.h>
 #include <linux/module.h>
 #include <linux/serial_core.h>
 #include <linux/slab.h>
@@ -112,6 +113,8 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
 	if (!ctrl_dev)
 		return ERR_PTR(-ENOMEM);
 
+	ida_init(&ctrl_dev->ida);
+
 	err = serial_base_device_init(port, &ctrl_dev->dev,
 				      parent, &serial_ctrl_type,
 				      serial_base_ctrl_release,
@@ -142,16 +145,31 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 						struct serial_ctrl_device *ctrl_dev)
 {
 	struct serial_port_device *port_dev;
+	unsigned int min = 0, max = ~0U;
 	int err;
 
 	port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
 	if (!port_dev)
 		return ERR_PTR(-ENOMEM);
 
+	/* Device driver specified port_id vs automatic assignment? */
+	if (port->port_id) {
+		min = port->port_id;
+		max = port->port_id;
+	}
+
+	err = ida_alloc_range(&ctrl_dev->ida, min, max, GFP_KERNEL);
+	if (err < 0) {
+		kfree(port_dev);
+		return ERR_PTR(err);
+	}
+
+	port->port_id = err;
+
 	err = serial_base_device_init(port, &port_dev->dev,
 				      &ctrl_dev->dev, &serial_port_type,
 				      serial_base_port_release,
-				      port->ctrl_id, port->line);
+				      port->ctrl_id, port->port_id);
 	if (err)
 		goto err_put_device;
 
@@ -165,16 +183,24 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 
 err_put_device:
 	put_device(&port_dev->dev);
+	ida_free(&ctrl_dev->ida, port->port_id);
 
 	return ERR_PTR(err);
 }
 
 void serial_base_port_device_remove(struct serial_port_device *port_dev)
 {
+	struct serial_ctrl_device *ctrl_dev;
+	struct device *parent;
+
 	if (!port_dev)
 		return;
 
+	parent = port_dev->dev.parent;
+	ctrl_dev = to_serial_base_ctrl_device(parent);
+
 	device_del(&port_dev->dev);
+	ida_free(&ctrl_dev->ida, port_dev->port->port_id);
 	put_device(&port_dev->dev);
 }
 
Signature · 1 line
2.41.0
#3 lore raw
Quoted 33 lines · Tony Lindgren

Hi,

Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Quoted 5 lines
Quoted 3 lines
Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")

Thanks for testing.

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

I'll send a proper patch assuming things test fine.

Regagrds,

Tony

8< --------------------

drivers/tty/serial/serial_base.h struct device; · line 19

Quoted 4 lines
drivers/tty/serial/serial_base.h +1 -0
@@ -16,6 +16,7 @@ struct device;
 
 struct serial_ctrl_device {
 	struct device dev;
+	struct ida ida;

When you send the proper patch, might want to change variable name to something other than ida?

[...]

Quoted 3 lines
Signature · 2 lines
-- 
2.41.0
Signature · 2 lines
Best regards,
Dhruva Gole <[email protected]>
#4 lore raw
Quoted 11 lines · Dhruva Gole

drivers/tty/serial/serial_base.h struct device; · line 19

Quoted 7 lines · Tony Lindgren
drivers/tty/serial/serial_base.h +1 -0
@@ -16,6 +16,7 @@ struct device;
 
 struct serial_ctrl_device {
 	struct device dev;
+	struct ida ida;

When you send the proper patch, might want to change variable name to something other than ida?

OK I'll change it to port_ida.

Tony

#5 lore raw
In reply to Tony Lindgren
Quoted 15 lines · Tony Lindgren

Hi,

Quoted 12 lines · Guenter Roeck
Quoted 10 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")
Quoted 7 lines
Quoted 1 line

Thanks for testing.

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

Queued. We should have test results sometime tomorrow.

Guenter

#6 lore raw
Quoted 18 lines · Guenter Roeck
Quoted 17 lines · Tony Lindgren

Hi,

Quoted 13 lines · Guenter Roeck
Quoted 10 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")
Quoted 7 lines
Quoted 5 lines

Thanks for testing.

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

Queued. We should have test results sometime tomorrow.

OK great.

Thanks,

Tony

Tested-by
#7 lore raw
In reply to Tony Lindgren
Quoted 15 lines · Tony Lindgren

Hi,

Quoted 12 lines · Guenter Roeck
Quoted 10 lines · Tony Lindgren

Guenter reports boot issues with duplicate sysfs entries for multiport drivers. Let's go back to using port->line for now to fix the regression.

With this change, the serial core port device names are not correct for the hardware specific 8250 single port drivers, but that's a cosmetic issue for now.

Fixes d962de6ae51f ("serial: core: Fix serial core port id to not use port->line")
Quoted 9 lines
Quoted 1 line

Thanks for testing.

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

I'll send a proper patch assuming things test fine.

Patch below works for me.

Guenter

Quoted 94 lines

Regagrds,

Tony

8< --------------------

drivers/tty/serial/serial_base.h +1 -0
@@ -16,6 +16,7 @@ struct device;
 
  struct serial_ctrl_device {
  	struct device dev;
+	struct ida ida;
  };
 
  struct serial_port_device {
drivers/tty/serial/serial_base_bus.c +27 -1
@@ -10,6 +10,7 @@
 
  #include <linux/container_of.h>
  #include <linux/device.h>
+#include <linux/idr.h>
  #include <linux/module.h>
  #include <linux/serial_core.h>
  #include <linux/slab.h>
@@ -112,6 +113,8 @@ struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port,
  	if (!ctrl_dev)
  		return ERR_PTR(-ENOMEM);
 
+	ida_init(&ctrl_dev->ida);
+
  	err = serial_base_device_init(port, &ctrl_dev->dev,
  				      parent, &serial_ctrl_type,
  				      serial_base_ctrl_release,
@@ -142,16 +145,31 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
  						struct serial_ctrl_device *ctrl_dev)
  {
  	struct serial_port_device *port_dev;
+	unsigned int min = 0, max = ~0U;
  	int err;
 
  	port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
  	if (!port_dev)
  		return ERR_PTR(-ENOMEM);
 
+	/* Device driver specified port_id vs automatic assignment? */
+	if (port->port_id) {
+		min = port->port_id;
+		max = port->port_id;
+	}
+
+	err = ida_alloc_range(&ctrl_dev->ida, min, max, GFP_KERNEL);
+	if (err < 0) {
+		kfree(port_dev);
+		return ERR_PTR(err);
+	}
+
+	port->port_id = err;
+
  	err = serial_base_device_init(port, &port_dev->dev,
  				      &ctrl_dev->dev, &serial_port_type,
  				      serial_base_port_release,
-				      port->ctrl_id, port->line);
+				      port->ctrl_id, port->port_id);
  	if (err)
  		goto err_put_device;
 
@@ -165,16 +183,24 @@ struct serial_port_device *serial_base_port_add(struct uart_port *port,
 
  err_put_device:
  	put_device(&port_dev->dev);
+	ida_free(&ctrl_dev->ida, port->port_id);
 
  	return ERR_PTR(err);
  }
 
  void serial_base_port_device_remove(struct serial_port_device *port_dev)
  {
+	struct serial_ctrl_device *ctrl_dev;
+	struct device *parent;
+
  	if (!port_dev)
  		return;
 
+	parent = port_dev->dev.parent;
+	ctrl_dev = to_serial_base_ctrl_device(parent);
+
  	device_del(&port_dev->dev);
+	ida_free(&ctrl_dev->ida, port_dev->port->port_id);
  	put_device(&port_dev->dev);
  }
 
#8 lore raw
Quoted 8 lines · Guenter Roeck
Quoted 5 lines · Tony Lindgren

Guenter, care to also test the patch below on top of this fix and see if things still behave for you?

I'll send a proper patch assuming things test fine.

Patch below works for me.

OK good to hear thanks, patch posted at [0] below.

Regards,

Tony

[0] https://lore.kernel.org/linux-serial/[email protected]/T/#u