2023-06-02 06:58:18

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH] 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")
Signed-off-by: Tony Lindgren <[email protected]>
---
drivers/tty/serial/serial_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -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;
}
--
2.41.0


2023-06-02 07:01:20

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH] serial: core: Fix error handling for serial_core_ctrl_device_add()

* Tony Lindgren <[email protected]> [230602 06:41]:
> 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")
> Signed-off-by: Tony Lindgren <[email protected]>
> ---
> drivers/tty/serial/serial_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -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

2023-06-02 07:01:53

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH] serial: core: Fix error handling for serial_core_ctrl_device_add()

On 02. 06. 23, 8:46, Tony Lindgren wrote:
> * Tony Lindgren <[email protected]> [230602 06:41]:
>> 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")
>> Signed-off-by: Tony Lindgren <[email protected]>
>> ---
>> drivers/tty/serial/serial_core.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
>> --- a/drivers/tty/serial/serial_core.c
>> +++ b/drivers/tty/serial/serial_core.c
>> @@ -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?

--
js
suse labs


2023-06-02 07:02:45

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH] serial: core: Fix error handling for serial_core_ctrl_device_add()

* Jiri Slaby <[email protected]> [230602 06:48]:
> On 02. 06. 23, 8:46, Tony Lindgren wrote:
> > * Tony Lindgren <[email protected]> [230602 06:41]:
> > > 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")
> > > Signed-off-by: Tony Lindgren <[email protected]>
> > > ---
> > > drivers/tty/serial/serial_core.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> > > --- a/drivers/tty/serial/serial_core.c
> > > +++ b/drivers/tty/serial/serial_core.c
> > > @@ -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?

Yup there should be no need for that thanks.

Regards,

Tony