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


Groups > linux.kernel > #1569383 > unrolled thread

[PATCH] iio: adc - Fix possible NULL derefrence.

Started byShailendra Verma <shailendra.v@samsung.com>
First post2017-01-30 05:50 +0100
Last post2017-01-30 13:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] iio: adc - Fix possible NULL derefrence. Shailendra Verma <shailendra.v@samsung.com> - 2017-01-30 05:50 +0100
    Re: [PATCH] iio: adc - Fix possible NULL derefrence. Marek Vasut <marex@denx.de> - 2017-01-30 13:20 +0100

#1569383 — [PATCH] iio: adc - Fix possible NULL derefrence.

FromShailendra Verma <shailendra.v@samsung.com>
Date2017-01-30 05:50 +0100
Subject[PATCH] iio: adc - Fix possible NULL derefrence.
Message-ID<t5c4F-7WV-21@gated-at.bofh.it>
of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/iio/adc/mxs-lradc.c       |   14 ++++++++++----
 drivers/iio/adc/rockchip_saradc.c |    4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/mxs-lradc.c b/drivers/iio/adc/mxs-lradc.c
index b84d37c..4308a59 100644
--- a/drivers/iio/adc/mxs-lradc.c
+++ b/drivers/iio/adc/mxs-lradc.c
@@ -1570,10 +1570,8 @@ static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc,
 
 static int mxs_lradc_probe(struct platform_device *pdev)
 {
-	const struct of_device_id *of_id =
-		of_match_device(mxs_lradc_dt_ids, &pdev->dev);
-	const struct mxs_lradc_of_config *of_cfg =
-		&mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
+	const struct of_device_id *of_id;
+	const struct mxs_lradc_of_config *of_cfg;
 	struct device *dev = &pdev->dev;
 	struct device_node *node = dev->of_node;
 	struct mxs_lradc *lradc;
@@ -1583,6 +1581,14 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 	int i, s;
 	u64 scale_uv;
 
+	of_id = of_match_device(mxs_lradc_dt_ids, &pdev->dev);
+	if (!of_id) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
+
+	of_cfg = &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
+
 	/* Allocate the IIO device. */
 	iio = devm_iio_device_alloc(dev, sizeof(*lradc));
 	if (!iio) {
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
index 85d7012..08dfb43 100644
--- a/drivers/iio/adc/rockchip_saradc.c
+++ b/drivers/iio/adc/rockchip_saradc.c
@@ -224,6 +224,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 	info = iio_priv(indio_dev);
 
 	match = of_match_device(rockchip_saradc_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
 	info->data = match->data;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
1.7.9.5

[toc] | [next] | [standalone]


#1569688

FromMarek Vasut <marex@denx.de>
Date2017-01-30 13:20 +0100
Message-ID<t5j6a-3SD-3@gated-at.bofh.it>
In reply to#1569383
On 01/30/2017 05:47 AM, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>

a) this should be two patches
b) same question as in case of the mmc patch -- The probe won't be
called if OF match doesn't happen in the first place, so this check is
redundant, no ?

> ---
>  drivers/iio/adc/mxs-lradc.c       |   14 ++++++++++----
>  drivers/iio/adc/rockchip_saradc.c |    4 ++++
>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/mxs-lradc.c b/drivers/iio/adc/mxs-lradc.c
> index b84d37c..4308a59 100644
> --- a/drivers/iio/adc/mxs-lradc.c
> +++ b/drivers/iio/adc/mxs-lradc.c
> @@ -1570,10 +1570,8 @@ static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc,
>  
>  static int mxs_lradc_probe(struct platform_device *pdev)
>  {
> -	const struct of_device_id *of_id =
> -		of_match_device(mxs_lradc_dt_ids, &pdev->dev);
> -	const struct mxs_lradc_of_config *of_cfg =
> -		&mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
> +	const struct of_device_id *of_id;
> +	const struct mxs_lradc_of_config *of_cfg;
>  	struct device *dev = &pdev->dev;
>  	struct device_node *node = dev->of_node;
>  	struct mxs_lradc *lradc;
> @@ -1583,6 +1581,14 @@ static int mxs_lradc_probe(struct platform_device *pdev)
>  	int i, s;
>  	u64 scale_uv;
>  
> +	of_id = of_match_device(mxs_lradc_dt_ids, &pdev->dev);
> +	if (!of_id) {
> +		dev_err(&pdev->dev, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
> +
> +	of_cfg = &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
> +
>  	/* Allocate the IIO device. */
>  	iio = devm_iio_device_alloc(dev, sizeof(*lradc));
>  	if (!iio) {
> diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
> index 85d7012..08dfb43 100644
> --- a/drivers/iio/adc/rockchip_saradc.c
> +++ b/drivers/iio/adc/rockchip_saradc.c
> @@ -224,6 +224,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
>  	info = iio_priv(indio_dev);
>  
>  	match = of_match_device(rockchip_saradc_match, &pdev->dev);
> +	if (!match) {
> +		dev_err(&pdev->dev, "Error: No device match found\n");
> +		return -ENODEV;
> +	}
>  	info->data = match->data;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> 


-- 
Best regards,
Marek Vasut

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web