Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1267685 > unrolled thread

[PATCH] serial: imx: fix a possible NULL dereference

Started byLABBE Corentin <clabbe.montjoie@gmail.com>
First post2015-11-12 08:50 +0100
Last post2015-11-16 13:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] serial: imx: fix a possible NULL dereference LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-11-12 08:50 +0100
    Re: [PATCH] serial: imx: fix a possible NULL dereference Uwe Kleine-König   <u.kleine-koenig@pengutronix.de> - 2015-11-16 13:20 +0100

#1267685 — [PATCH] serial: imx: fix a possible NULL dereference

FromLABBE Corentin <clabbe.montjoie@gmail.com>
Date2015-11-12 08:50 +0100
Subject[PATCH] serial: imx: fix a possible NULL dereference
Message-ID<qtUNQ-5ZA-11@gated-at.bofh.it>
of_match_device could return NULL, and so cause a NULL pointer
dereference later.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 drivers/tty/serial/imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 016e4be..22e91f7 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1857,8 +1857,7 @@ static int serial_imx_probe_dt(struct imx_port *sport,
 		struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	const struct of_device_id *of_id =
-			of_match_device(imx_uart_dt_ids, &pdev->dev);
+	const struct of_device_id *of_id;
 	int ret;
 
 	if (!np)
@@ -1878,6 +1877,9 @@ static int serial_imx_probe_dt(struct imx_port *sport,
 	if (of_get_property(np, "fsl,dte-mode", NULL))
 		sport->dte_mode = 1;
 
+	of_id = of_match_device(imx_uart_dt_ids, &pdev->dev);
+	if (!of_id)
+		return -ENODEV;
 	sport->devdata = of_id->data;
 
 	return 0;
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1270061

FromUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date2015-11-16 13:20 +0100
Message-ID<qvqVk-7cN-27@gated-at.bofh.it>
In reply to#1267685
Hello,

On Thu, Nov 12, 2015 at 08:46:21AM +0100, LABBE Corentin wrote:
> of_match_device could return NULL, and so cause a NULL pointer
> dereference later.
> 
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---
>  drivers/tty/serial/imx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 016e4be..22e91f7 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -1857,8 +1857,7 @@ static int serial_imx_probe_dt(struct imx_port *sport,
>  		struct platform_device *pdev)
>  {
>  	struct device_node *np = pdev->dev.of_node;
> -	const struct of_device_id *of_id =
> -			of_match_device(imx_uart_dt_ids, &pdev->dev);
> +	const struct of_device_id *of_id;
>  	int ret;
>  
>  	if (!np)
> @@ -1878,6 +1877,9 @@ static int serial_imx_probe_dt(struct imx_port *sport,
>  	if (of_get_property(np, "fsl,dte-mode", NULL))
>  		sport->dte_mode = 1;
>  
> +	of_id = of_match_device(imx_uart_dt_ids, &pdev->dev);
> +	if (!of_id)
> +		return -ENODEV;
>  	sport->devdata = of_id->data;
>  
>  	return 0;

I'd do something like:

-	if (!np)
+	sport->devdata = of_device_get_match_data(&pdev->dev);
+	if (!sport->devdata)
 		/* no device tree device */
 		return 1;

instead.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web