linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port()
@ 2023-10-18  9:12 Yi Yang
  2023-10-18 18:28 ` Hugo Villeneuve
  2023-10-18 18:35 ` Hugo Villeneuve
  0 siblings, 2 replies; 4+ messages in thread
From: Yi Yang @ 2023-10-18  9:12 UTC (permalink / raw)
  To: gregkh, jirislaby, srinivas.kandagatla; +Cc: linux-arm-kernel, linux-serial

The platform_get_irq() might be failed and return a negative result, there
should be return an error code when platform_get_irq() failed.
Fix it by add check return value of platform_get_irq().

Fixes: c4b058560762 ("serial:st-asc: Add ST ASC driver.")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/tty/serial/st-asc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index a821f5d76a26..8321167502dc 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -683,12 +683,16 @@ static int asc_init_port(struct asc_port *ascport,
 	struct resource *res;
 	int ret;
 
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;
+
 	port->iotype	= UPIO_MEM;
 	port->flags	= UPF_BOOT_AUTOCONF;
 	port->ops	= &asc_uart_ops;
 	port->fifosize	= ASC_FIFO_SIZE;
 	port->dev	= &pdev->dev;
-	port->irq	= platform_get_irq(pdev, 0);
+	port->irq	= ret;
 	port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE);
 
 	port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port()
  2023-10-18  9:12 [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port() Yi Yang
@ 2023-10-18 18:28 ` Hugo Villeneuve
  2023-10-19  5:02   ` Jiri Slaby
  2023-10-18 18:35 ` Hugo Villeneuve
  1 sibling, 1 reply; 4+ messages in thread
From: Hugo Villeneuve @ 2023-10-18 18:28 UTC (permalink / raw)
  To: Yi Yang
  Cc: gregkh, jirislaby, srinivas.kandagatla, linux-arm-kernel,
	linux-serial

On Wed, 18 Oct 2023 09:12:40 +0000
Yi Yang <yiyang13@huawei.com> wrote:

> The platform_get_irq() might be failed and return a negative result, there
> should be return an error code when platform_get_irq() failed.
> Fix it by add check return value of platform_get_irq().
> 
> Fixes: c4b058560762 ("serial:st-asc: Add ST ASC driver.")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/tty/serial/st-asc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
> index a821f5d76a26..8321167502dc 100644
> --- a/drivers/tty/serial/st-asc.c
> +++ b/drivers/tty/serial/st-asc.c
> @@ -683,12 +683,16 @@ static int asc_init_port(struct asc_port *ascport,
>  	struct resource *res;
>  	int ret;
>  
> +	ret = platform_get_irq(pdev, 0);

Hi,
for readability, you could define a new irq variable instead of using
ret. See reasoning below.

> +	if (ret < 0)
> +		return ret;
> +
>  	port->iotype	= UPIO_MEM;
>  	port->flags	= UPF_BOOT_AUTOCONF;
>  	port->ops	= &asc_uart_ops;
>  	port->fifosize	= ASC_FIFO_SIZE;
>  	port->dev	= &pdev->dev;
> -	port->irq	= platform_get_irq(pdev, 0);
> +	port->irq	= ret;

Assigning port->irq to irq instead of ret will make the code more
understandable.

You could do the same change for your other patch (atmel).

Hugo.


>  	port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE);
>  
>  	port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> -- 
> 2.25.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port()
  2023-10-18  9:12 [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port() Yi Yang
  2023-10-18 18:28 ` Hugo Villeneuve
@ 2023-10-18 18:35 ` Hugo Villeneuve
  1 sibling, 0 replies; 4+ messages in thread
From: Hugo Villeneuve @ 2023-10-18 18:35 UTC (permalink / raw)
  To: Yi Yang
  Cc: gregkh, jirislaby, srinivas.kandagatla, linux-arm-kernel,
	linux-serial

On Wed, 18 Oct 2023 09:12:40 +0000
Yi Yang <yiyang13@huawei.com> wrote:

Hi,

> The platform_get_irq() might be failed and return a negative result, there

Change to:

"platform_get_irq() might fail and return a negative result."

> should be return an error code when platform_get_irq() failed.
> Fix it by add check return value of platform_get_irq().

and maybe something along:

"Return an error code when platform_get_irq() fails."

Hugo.

 
> Fixes: c4b058560762 ("serial:st-asc: Add ST ASC driver.")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/tty/serial/st-asc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
> index a821f5d76a26..8321167502dc 100644
> --- a/drivers/tty/serial/st-asc.c
> +++ b/drivers/tty/serial/st-asc.c
> @@ -683,12 +683,16 @@ static int asc_init_port(struct asc_port *ascport,
>  	struct resource *res;
>  	int ret;
>  
> +	ret = platform_get_irq(pdev, 0);
> +	if (ret < 0)
> +		return ret;
> +
>  	port->iotype	= UPIO_MEM;
>  	port->flags	= UPF_BOOT_AUTOCONF;
>  	port->ops	= &asc_uart_ops;
>  	port->fifosize	= ASC_FIFO_SIZE;
>  	port->dev	= &pdev->dev;
> -	port->irq	= platform_get_irq(pdev, 0);
> +	port->irq	= ret;
>  	port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE);
>  
>  	port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> -- 
> 2.25.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port()
  2023-10-18 18:28 ` Hugo Villeneuve
@ 2023-10-19  5:02   ` Jiri Slaby
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2023-10-19  5:02 UTC (permalink / raw)
  To: Hugo Villeneuve, Yi Yang
  Cc: gregkh, srinivas.kandagatla, linux-arm-kernel, linux-serial

On 18. 10. 23, 20:28, Hugo Villeneuve wrote:
> On Wed, 18 Oct 2023 09:12:40 +0000
> Yi Yang <yiyang13@huawei.com> wrote:
> 
>> The platform_get_irq() might be failed and return a negative result, there
>> should be return an error code when platform_get_irq() failed.
>> Fix it by add check return value of platform_get_irq().
>>
>> Fixes: c4b058560762 ("serial:st-asc: Add ST ASC driver.")
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>>   drivers/tty/serial/st-asc.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
>> index a821f5d76a26..8321167502dc 100644
>> --- a/drivers/tty/serial/st-asc.c
>> +++ b/drivers/tty/serial/st-asc.c
>> @@ -683,12 +683,16 @@ static int asc_init_port(struct asc_port *ascport,
>>   	struct resource *res;
>>   	int ret;
>>   
>> +	ret = platform_get_irq(pdev, 0);
> 
> Hi,
> for readability, you could define a new irq variable instead of using
> ret. See reasoning below.
> 
>> +	if (ret < 0)
>> +		return ret;
>> +
>>   	port->iotype	= UPIO_MEM;
>>   	port->flags	= UPF_BOOT_AUTOCONF;
>>   	port->ops	= &asc_uart_ops;
>>   	port->fifosize	= ASC_FIFO_SIZE;
>>   	port->dev	= &pdev->dev;
>> -	port->irq	= platform_get_irq(pdev, 0);
>> +	port->irq	= ret;
> 
> Assigning port->irq to irq instead of ret will make the code more
> understandable.

Yes. And you need not to worry that someone will stick another
ret = something();
after platform_get_irq() above.

thanks,
-- 
js
suse labs


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-19  5:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18  9:12 [PATCH] serial: st-asc: Check return value of platform_get_irq() in asc_init_port() Yi Yang
2023-10-18 18:28 ` Hugo Villeneuve
2023-10-19  5:02   ` Jiri Slaby
2023-10-18 18:35 ` Hugo Villeneuve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).