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


Groups > linux.kernel > #1277361 > unrolled thread

[PATCH] ASoC: rsnd: fix a possible NULL dereference

Started byLABBE Corentin <clabbe.montjoie@gmail.com>
First post2015-11-25 14:00 +0100
Last post2015-11-30 17:40 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] ASoC: rsnd: fix a possible NULL dereference LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-11-25 14:00 +0100
    Re: [PATCH] ASoC: rsnd: fix a possible NULL dereference Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> - 2015-11-26 00:50 +0100
      Re: [PATCH] ASoC: rsnd: fix a possible NULL dereference LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-11-26 08:20 +0100
        Re: [PATCH] ASoC: rsnd: fix a possible NULL dereference Mark Brown <broonie@kernel.org> - 2015-11-30 17:40 +0100

#1277361 — [PATCH] ASoC: rsnd: fix a possible NULL dereference

FromLABBE Corentin <clabbe.montjoie@gmail.com>
Date2015-11-25 14:00 +0100
Subject[PATCH] ASoC: rsnd: fix a possible NULL dereference
Message-ID<qyHPX-6p2-1@gated-at.bofh.it>
of_match_device could return NULL, and so cause a NULL pointer
dereference later.
Even if the probability of this case is very low, fixing it made
static analyzers happy.
Solving this with of_device_get_match_data made also code simplier.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 sound/soc/sh/rcar/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index deed48e..54cc44c 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -1204,7 +1204,6 @@ static int rsnd_probe(struct platform_device *pdev)
 	struct rsnd_priv *priv;
 	struct device *dev = &pdev->dev;
 	struct rsnd_dai *rdai;
-	const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
 	const struct rsnd_of_data *of_data;
 	int (*probe_func[])(struct platform_device *pdev,
 			    const struct rsnd_of_data *of_data,
@@ -1221,11 +1220,13 @@ static int rsnd_probe(struct platform_device *pdev)
 	};
 	int ret, i;
 
+	of_data = of_device_get_match_data(dev);
+	if (!of_data)
+		return 1;
 	info = devm_kzalloc(&pdev->dev, sizeof(struct rcar_snd_info),
 			    GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
-	of_data = of_id->data;
 
 	/*
 	 *	init priv data
-- 
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]


#1277888

FromKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date2015-11-26 00:50 +0100
Message-ID<qyRZ0-4Aw-17@gated-at.bofh.it>
In reply to#1277361
Hi LABBE

Thank you for your patch

> of_match_device could return NULL, and so cause a NULL pointer
> dereference later.
> Even if the probability of this case is very low, fixing it made
> static analyzers happy.
> Solving this with of_device_get_match_data made also code simplier.
> 
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---
>  sound/soc/sh/rcar/core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
> index deed48e..54cc44c 100644
> --- a/sound/soc/sh/rcar/core.c
> +++ b/sound/soc/sh/rcar/core.c
> @@ -1204,7 +1204,6 @@ static int rsnd_probe(struct platform_device *pdev)
>  	struct rsnd_priv *priv;
>  	struct device *dev = &pdev->dev;
>  	struct rsnd_dai *rdai;
> -	const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
>  	const struct rsnd_of_data *of_data;
>  	int (*probe_func[])(struct platform_device *pdev,
>  			    const struct rsnd_of_data *of_data,
> @@ -1221,11 +1220,13 @@ static int rsnd_probe(struct platform_device *pdev)
>  	};
>  	int ret, i;
>  
> +	of_data = of_device_get_match_data(dev);
> +	if (!of_data)
> +		return 1;

return 1 ?
You want to use -EINVAL ?

--
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] | [next] | [standalone]


#1278014

FromLABBE Corentin <clabbe.montjoie@gmail.com>
Date2015-11-26 08:20 +0100
Message-ID<qyZ0u-1Eu-9@gated-at.bofh.it>
In reply to#1277888
On Wed, Nov 25, 2015 at 11:46:45PM +0000, Kuninori Morimoto wrote:
> 
> Hi LABBE
> 
> Thank you for your patch
> 
> > of_match_device could return NULL, and so cause a NULL pointer
> > dereference later.
> > Even if the probability of this case is very low, fixing it made
> > static analyzers happy.
> > Solving this with of_device_get_match_data made also code simplier.
> > 
> > Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> > ---
> >  sound/soc/sh/rcar/core.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
> > index deed48e..54cc44c 100644
> > --- a/sound/soc/sh/rcar/core.c
> > +++ b/sound/soc/sh/rcar/core.c
> > @@ -1204,7 +1204,6 @@ static int rsnd_probe(struct platform_device *pdev)
> >  	struct rsnd_priv *priv;
> >  	struct device *dev = &pdev->dev;
> >  	struct rsnd_dai *rdai;
> > -	const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
> >  	const struct rsnd_of_data *of_data;
> >  	int (*probe_func[])(struct platform_device *pdev,
> >  			    const struct rsnd_of_data *of_data,
> > @@ -1221,11 +1220,13 @@ static int rsnd_probe(struct platform_device *pdev)
> >  	};
> >  	int ret, i;
> >  
> > +	of_data = of_device_get_match_data(dev);
> > +	if (!of_data)
> > +		return 1;
> 
> return 1 ?
> You want to use -EINVAL ?
> 

I do that Uwe Kleine-König said to me to do in others thread:
https://lkml.org/lkml/2015/11/12/70 and https://lkml.org/lkml/2015/11/16/211

Regards

--
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] | [next] | [standalone]


#1280089

FromMark Brown <broonie@kernel.org>
Date2015-11-30 17:40 +0100
Message-ID<qAzEC-62E-3@gated-at.bofh.it>
In reply to#1278014

[Multipart message — attachments visible in raw view] — view raw

On Thu, Nov 26, 2015 at 08:17:15AM +0100, LABBE Corentin wrote:
> On Wed, Nov 25, 2015 at 11:46:45PM +0000, Kuninori Morimoto wrote:

> > > +	of_data = of_device_get_match_data(dev);
> > > +	if (!of_data)
> > > +		return 1;

> > return 1 ?
> > You want to use -EINVAL ?

> I do that Uwe Kleine-König said to me to do in others thread:
> https://lkml.org/lkml/2015/11/12/70 and https://lkml.org/lkml/2015/11/16/211

What error code to return is going to depend on the context - you need
to look at what the caller is expecting and how it will handle the value
returned.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web