Skip to contentSkip to conversation

serial: core: Fix error handling for serial_core_ctrl_device_add()

PATCH In review Tony Lindgren 3 participants 3 messages Jun 2, 2023 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: core: Fix error handling for serial_core_ctrl_device_add()

Checking for NULL is incorrect as serial_base_ctrl_add() uses ERR_PTR().

Let's also pass any returned error along, there's no reason to translate all errors to -ENODEV.

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")

---

Changes since v1:

- Stop translating all errors to -ENODEV

- There's no need to use IS_ERR_OR_NULL() as noted by Jiri

---
 drivers/tty/serial/serial_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +2 -2
@@ -3342,8 +3342,8 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
 	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
 	if (!ctrl_dev) {
 		new_ctrl_dev = serial_core_ctrl_device_add(port);
-		if (!new_ctrl_dev) {
-			ret = -ENODEV;
+		if (IS_ERR(new_ctrl_dev)) {
+			ret = PTR_ERR(new_ctrl_dev);
 			goto err_unlock;
 		}
 		ctrl_dev = new_ctrl_dev;
Signature · 1 line
2.41.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Tony Lindgren

Checking for NULL is incorrect as serial_base_ctrl_add() uses ERR_PTR().

Let's also pass any returned error along, there's no reason to translate all errors to -ENODEV.

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")

thanks,

Signature · 2 lines
js
suse labs
Reviewed-by on v2 1/1
#2 lore raw
In reply to Tony Lindgren
Quoted 4 lines · Tony Lindgren

Checking for NULL is incorrect as serial_base_ctrl_add() uses ERR_PTR().

Let's also pass any returned error along, there's no reason to translate all errors to -ENODEV.

Jiri already asked the same question I have had on a glance, and this all solved here, so

Quoted 30 lines
Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")

---

Changes since v1:

- Stop translating all errors to -ENODEV

- There's no need to use IS_ERR_OR_NULL() as noted by Jiri

---
 drivers/tty/serial/serial_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +2 -2
@@ -3342,8 +3342,8 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
 	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
 	if (!ctrl_dev) {
 		new_ctrl_dev = serial_core_ctrl_device_add(port);
-		if (!new_ctrl_dev) {
-			ret = -ENODEV;
+		if (IS_ERR(new_ctrl_dev)) {
+			ret = PTR_ERR(new_ctrl_dev);
 			goto err_unlock;
 		}
 		ctrl_dev = new_ctrl_dev;
Signature · 1 line
2.41.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko