All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Shailendra Verma <shailendra.v@samsung.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Heiko Stuebner <heiko@sntech.de>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Ksenija Stanojevic <ksenija.stanojevic@gmail.com>,
	linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	p.shailesh@samsung.com, ashish.kalra@samsung.com,
	Shailendra Verma <shailendra.capricorn@gmail.com>
Subject: Re: [PATCH] iio: adc - Fix possible NULL derefrence.
Date: Mon, 30 Jan 2017 13:13:22 +0100	[thread overview]
Message-ID: <a4f4f5fc-5a00-5a39-8c2a-999686196a45@denx.de> (raw)
In-Reply-To: <1485751634-28963-1-git-send-email-shailendra.v@samsung.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
To: Shailendra Verma
	<shailendra.v-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Peter Meerwald-Stadler
	<pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
	Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>,
	Dmitry Torokhov
	<dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Ksenija Stanojevic
	<ksenija.stanojevic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	p.shailesh-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	ashish.kalra-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	Shailendra Verma
	<shailendra.capricorn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH] iio: adc - Fix possible NULL derefrence.
Date: Mon, 30 Jan 2017 13:13:22 +0100	[thread overview]
Message-ID: <a4f4f5fc-5a00-5a39-8c2a-999686196a45@denx.de> (raw)
In-Reply-To: <1485751634-28963-1-git-send-email-shailendra.v-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>

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-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>

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

WARNING: multiple messages have this Message-ID (diff)
From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] iio: adc - Fix possible NULL derefrence.
Date: Mon, 30 Jan 2017 13:13:22 +0100	[thread overview]
Message-ID: <a4f4f5fc-5a00-5a39-8c2a-999686196a45@denx.de> (raw)
In-Reply-To: <1485751634-28963-1-git-send-email-shailendra.v@samsung.com>

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

  reply	other threads:[~2017-01-30 12:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170130044724epcas3p444b23d43fed213511e6994ecb4ed0ef3@epcas3p4.samsung.com>
2017-01-30  4:47 ` [PATCH] iio: adc - Fix possible NULL derefrence Shailendra Verma
2017-01-30  4:47   ` Shailendra Verma
2017-01-30  4:47   ` Shailendra Verma
2017-01-30 12:13   ` Marek Vasut [this message]
2017-01-30 12:13     ` Marek Vasut
2017-01-30 12:13     ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a4f4f5fc-5a00-5a39-8c2a-999686196a45@denx.de \
    --to=marex@denx.de \
    --cc=ashish.kalra@samsung.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=heiko@sntech.de \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=ksenija.stanojevic@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=p.shailesh@samsung.com \
    --cc=pmeerw@pmeerw.net \
    --cc=shailendra.capricorn@gmail.com \
    --cc=shailendra.v@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.