diff mbox series

fsl_lpuart: Don't enable interrupts too early

Message ID 20220505114750.45423-1-Indan.Zupancic@mep-info.com
State New
Headers show
Series fsl_lpuart: Don't enable interrupts too early | expand

Commit Message

Indan Zupancic May 5, 2022, 11:47 a.m. UTC
If an irq is pending when devm_request_irq() is called, the irq
handler will cause a NULL pointer access because initialisation
is not done yet.

Fixes: 9d7ee0e28da59 ("tty: serial: lpuart: avoid report NULL interrupt")
Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
---
 drivers/tty/serial/fsl_lpuart.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Sherry Sun May 6, 2022, 12:22 p.m. UTC | #1
> -----Original Message-----
> From: Indan Zupancic <Indan.Zupancic@mep-info.com>
> Sent: 2022年5月5日 19:48
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Sherry Sun <sherry.sun@nxp.com>; dl-linux-imx <linux-imx@nxp.com>;
> linux-serial@vger.kernel.org; jirislaby@kernel.org; Indan Zupancic
> <Indan.Zupancic@mep-info.com>
> Subject: [PATCH] fsl_lpuart: Don't enable interrupts too early
> 
> If an irq is pending when devm_request_irq() is called, the irq handler will
> cause a NULL pointer access because initialisation is not done yet.
> 
> Fixes: 9d7ee0e28da59 ("tty: serial: lpuart: avoid report NULL interrupt")
> Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>

Reviewed-by: Sherry Sun <sherry.sun@nxp.com>

Best regards
Sherry

> ---
>  drivers/tty/serial/fsl_lpuart.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 75b3c36c13bc..7b46b97a6ddd 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -2629,6 +2629,7 @@ static int lpuart_probe(struct platform_device
> *pdev)
>  	struct device_node *np = pdev->dev.of_node;
>  	struct lpuart_port *sport;
>  	struct resource *res;
> +	irq_handler_t handler;
>  	int ret;
> 
>  	sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); @@
> -2701,17 +2702,11 @@ static int lpuart_probe(struct platform_device *pdev)
> 
>  	if (lpuart_is_32(sport)) {
>  		lpuart_reg.cons = LPUART32_CONSOLE;
> -		ret = devm_request_irq(&pdev->dev, sport->port.irq,
> lpuart32_int, 0,
> -					DRIVER_NAME, sport);
> +		handler = lpuart32_int;
>  	} else {
>  		lpuart_reg.cons = LPUART_CONSOLE;
> -		ret = devm_request_irq(&pdev->dev, sport->port.irq,
> lpuart_int, 0,
> -					DRIVER_NAME, sport);
> +		handler = lpuart_int;
>  	}
> -
> -	if (ret)
> -		goto failed_irq_request;
> -
>  	ret = uart_add_one_port(&lpuart_reg, &sport->port);
>  	if (ret)
>  		goto failed_attach_port;
> @@ -2733,13 +2728,18 @@ static int lpuart_probe(struct platform_device
> *pdev)
> 
>  	sport->port.rs485_config(&sport->port, &sport->port.rs485);
> 
> +	ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
> +				DRIVER_NAME, sport);
> +	if (ret)
> +		goto failed_irq_request;
> +
>  	return 0;
> 
> +failed_irq_request:
>  failed_get_rs485:
>  failed_reset:
>  	uart_remove_one_port(&lpuart_reg, &sport->port);
>  failed_attach_port:
> -failed_irq_request:
>  	lpuart_disable_clks(sport);
>  	return ret;
>  }
> --
> 2.30.2
Jiri Slaby (SUSE) May 9, 2022, 10:21 a.m. UTC | #2
On 05. 05. 22, 13:47, Indan Zupancic wrote:
> If an irq is pending when devm_request_irq() is called, the irq
> handler will cause a NULL pointer access because initialisation
> is not done yet.

Sounds about right. But could you be a bit more specific? Like appending 
the BUG and its stack trace?

> Fixes: 9d7ee0e28da59 ("tty: serial: lpuart: avoid report NULL interrupt")
> Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
> ---
>   drivers/tty/serial/fsl_lpuart.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 75b3c36c13bc..7b46b97a6ddd 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -2629,6 +2629,7 @@ static int lpuart_probe(struct platform_device *pdev)
>   	struct device_node *np = pdev->dev.of_node;
>   	struct lpuart_port *sport;
>   	struct resource *res;
> +	irq_handler_t handler;
>   	int ret;
>   
>   	sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
> @@ -2701,17 +2702,11 @@ static int lpuart_probe(struct platform_device *pdev)
>   
>   	if (lpuart_is_32(sport)) {
>   		lpuart_reg.cons = LPUART32_CONSOLE;
> -		ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart32_int, 0,
> -					DRIVER_NAME, sport);
> +		handler = lpuart32_int;
>   	} else {
>   		lpuart_reg.cons = LPUART_CONSOLE;
> -		ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart_int, 0,
> -					DRIVER_NAME, sport);
> +		handler = lpuart_int;
>   	}
> -
> -	if (ret)
> -		goto failed_irq_request;
> -
>   	ret = uart_add_one_port(&lpuart_reg, &sport->port);
>   	if (ret)
>   		goto failed_attach_port;
> @@ -2733,13 +2728,18 @@ static int lpuart_probe(struct platform_device *pdev)
>   
>   	sport->port.rs485_config(&sport->port, &sport->port.rs485);
>   
> +	ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
> +				DRIVER_NAME, sport);
> +	if (ret)
> +		goto failed_irq_request;
> +
>   	return 0;
>   
> +failed_irq_request:
>   failed_get_rs485:
>   failed_reset:
>   	uart_remove_one_port(&lpuart_reg, &sport->port);
>   failed_attach_port:
> -failed_irq_request:
>   	lpuart_disable_clks(sport);
>   	return ret;
>   }
diff mbox series

Patch

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 75b3c36c13bc..7b46b97a6ddd 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -2629,6 +2629,7 @@  static int lpuart_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct lpuart_port *sport;
 	struct resource *res;
+	irq_handler_t handler;
 	int ret;
 
 	sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
@@ -2701,17 +2702,11 @@  static int lpuart_probe(struct platform_device *pdev)
 
 	if (lpuart_is_32(sport)) {
 		lpuart_reg.cons = LPUART32_CONSOLE;
-		ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart32_int, 0,
-					DRIVER_NAME, sport);
+		handler = lpuart32_int;
 	} else {
 		lpuart_reg.cons = LPUART_CONSOLE;
-		ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart_int, 0,
-					DRIVER_NAME, sport);
+		handler = lpuart_int;
 	}
-
-	if (ret)
-		goto failed_irq_request;
-
 	ret = uart_add_one_port(&lpuart_reg, &sport->port);
 	if (ret)
 		goto failed_attach_port;
@@ -2733,13 +2728,18 @@  static int lpuart_probe(struct platform_device *pdev)
 
 	sport->port.rs485_config(&sport->port, &sport->port.rs485);
 
+	ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
+				DRIVER_NAME, sport);
+	if (ret)
+		goto failed_irq_request;
+
 	return 0;
 
+failed_irq_request:
 failed_get_rs485:
 failed_reset:
 	uart_remove_one_port(&lpuart_reg, &sport->port);
 failed_attach_port:
-failed_irq_request:
 	lpuart_disable_clks(sport);
 	return ret;
 }