Skip to contentSkip to conversation

serial: core: Fix error handling for serial_core_ctrl_device_add()

PATCH Superseded Tony Lindgren 2 participants 4 messages Jun 2, 2023 TTY layer and serial drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

Checking for NULL is not enough as serial_base_ctrl_add() uses ERR_PTR().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +1 -1
@@ -3342,7 +3342,7 @@ 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) {
+		if (IS_ERR_OR_NULL(new_ctrl_dev)) {
 			ret = -ENODEV;
 			goto err_unlock;
 		}
Signature · 1 line
2.41.0
#1 lore raw
Quoted 12 lines · Tony Lindgren

Checking for NULL is not enough as serial_base_ctrl_add() uses ERR_PTR().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

drivers/tty/serial/serial_core.c int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) · line 3348

Quoted 8 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -3342,7 +3342,7 @@ 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) {
+		if (IS_ERR_OR_NULL(new_ctrl_dev)) {
 			ret = -ENODEV;
 			goto err_unlock;
 		}

Hmm actually we should also change to use ret = PTR_ERR(new_ctrl_dev) here instead of translating all the errors to -ENODEV. Will send out v2 version.

Regards,

Tony

maintainer
#2 lore raw
Quoted 9 lines · Tony Lindgren
Quoted 8 lines · Tony Lindgren

Checking for NULL is not enough as serial_base_ctrl_add() uses ERR_PTR().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
  drivers/tty/serial/serial_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/tty/serial/serial_core.c int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) · line 3348

Quoted 12 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -3342,7 +3342,7 @@ 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) {
+		if (IS_ERR_OR_NULL(new_ctrl_dev)) {
  			ret = -ENODEV;
  			goto err_unlock;
  		}

Hmm actually we should also change to use ret = PTR_ERR(new_ctrl_dev) here instead of translating all the errors to -ENODEV. Will send out v2 version.

Why OR_NULL at all, actually?

Signature · 2 lines
js
suse labs
#3 lore raw
Quoted 26 lines · Jiri Slaby
Quoted 9 lines · Tony Lindgren
Quoted 8 lines · Tony Lindgren

Checking for NULL is not enough as serial_base_ctrl_add() uses ERR_PTR().

Fixes 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
---
  drivers/tty/serial/serial_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/tty/serial/serial_core.c int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) · line 3348

Quoted 12 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -3342,7 +3342,7 @@ 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) {
+		if (IS_ERR_OR_NULL(new_ctrl_dev)) {
  			ret = -ENODEV;
  			goto err_unlock;
  		}

Hmm actually we should also change to use ret = PTR_ERR(new_ctrl_dev) here instead of translating all the errors to -ENODEV. Will send out v2 version.

Quoted 1 line

Why OR_NULL at all, actually?

Yup there should be no need for that thanks.

Regards,

Tony