All of lore.kernel.org
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/4] pinctrl: nomadik: Prevent NULL dereference if of_match_device returns NULL
Date: Thu, 15 Nov 2012 15:15:41 +0000	[thread overview]
Message-ID: <20121115151541.GC14476@gmail.com> (raw)
In-Reply-To: <CACRpkdbWqFrP7RvXbaR5Bcz1htCL_wSqwUvOi67LmoF_PBjvhg@mail.gmail.com>

On Thu, 15 Nov 2012, Linus Walleij wrote:

> On Thu, Nov 15, 2012 at 5:56 AM, Axel Lin <axel.lin@ingics.com> wrote:
> 
> > of_match_device() may return NULL.
> >
> > Signed-off-by: Axel Lin <axel.lin@ingics.com>
> > ---
> >  drivers/pinctrl/pinctrl-nomadik.c |   11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c
> > index 238060e..40bd1b3 100644
> > --- a/drivers/pinctrl/pinctrl-nomadik.c
> > +++ b/drivers/pinctrl/pinctrl-nomadik.c
> > @@ -1863,9 +1863,14 @@ static int __devinit nmk_pinctrl_probe(struct platform_device *pdev)
> >
> >         if (platid)
> >                 version = platid->driver_data;
> > -       else if (np)
> > -               version = (unsigned int)
> > -                       of_match_device(nmk_pinctrl_match, &pdev->dev)->data;
> > +       else if (np) {
> > +               const struct of_device_id *match;
> > +
> > +               match = of_match_device(nmk_pinctrl_match, &pdev->dev);
> > +               if (!match)
> > +                       return -ENODEV;
> > +               version = (unsigned int) match->data;
> > +       }
> 
> AFAICT this can actually happen so patch applied, unless Lee
> speaks against it.

At the very least it make the code easy to read.

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

WARNING: multiple messages have this Message-ID (diff)
From: Lee Jones <lee.jones@linaro.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Axel Lin <axel.lin@ingics.com>,
	Patrice Chotard <patrice.chotard@stericsson.com>,
	Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 4/4] pinctrl: nomadik: Prevent NULL dereference if of_match_device returns NULL
Date: Thu, 15 Nov 2012 15:15:41 +0000	[thread overview]
Message-ID: <20121115151541.GC14476@gmail.com> (raw)
In-Reply-To: <CACRpkdbWqFrP7RvXbaR5Bcz1htCL_wSqwUvOi67LmoF_PBjvhg@mail.gmail.com>

On Thu, 15 Nov 2012, Linus Walleij wrote:

> On Thu, Nov 15, 2012 at 5:56 AM, Axel Lin <axel.lin@ingics.com> wrote:
> 
> > of_match_device() may return NULL.
> >
> > Signed-off-by: Axel Lin <axel.lin@ingics.com>
> > ---
> >  drivers/pinctrl/pinctrl-nomadik.c |   11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c
> > index 238060e..40bd1b3 100644
> > --- a/drivers/pinctrl/pinctrl-nomadik.c
> > +++ b/drivers/pinctrl/pinctrl-nomadik.c
> > @@ -1863,9 +1863,14 @@ static int __devinit nmk_pinctrl_probe(struct platform_device *pdev)
> >
> >         if (platid)
> >                 version = platid->driver_data;
> > -       else if (np)
> > -               version = (unsigned int)
> > -                       of_match_device(nmk_pinctrl_match, &pdev->dev)->data;
> > +       else if (np) {
> > +               const struct of_device_id *match;
> > +
> > +               match = of_match_device(nmk_pinctrl_match, &pdev->dev);
> > +               if (!match)
> > +                       return -ENODEV;
> > +               version = (unsigned int) match->data;
> > +       }
> 
> AFAICT this can actually happen so patch applied, unless Lee
> speaks against it.

At the very least it make the code easy to read.

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

  reply	other threads:[~2012-11-15 15:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-15  4:51 [PATCH 1/4] pinctrl: dove: Prevent NULL dereference if of_match_device returns NULL Axel Lin
2012-11-15  4:51 ` Axel Lin
2012-11-15  4:52 ` [PATCH 2/4] pinctrl: kirkwood: " Axel Lin
2012-11-15  4:52   ` Axel Lin
2012-11-15 19:18   ` Thomas Petazzoni
2012-11-15 19:18     ` Thomas Petazzoni
2012-11-15  4:54 ` [PATCH 3/4] pinctrl: at91: " Axel Lin
2012-11-15  4:54   ` Axel Lin
2012-11-15  4:58   ` [PATCH RESEND " Axel Lin
2012-11-15  4:58     ` Axel Lin
2012-11-15  8:23     ` Nicolas Ferre
2012-11-15  8:23       ` Nicolas Ferre
2012-11-15 10:00     ` Jean-Christophe PLAGNIOL-VILLARD
2012-11-15 10:00       ` Jean-Christophe PLAGNIOL-VILLARD
2012-11-16  8:36       ` Nicolas Ferre
2012-11-16  8:36         ` Nicolas Ferre
2012-11-16  9:39         ` Jean-Christophe PLAGNIOL-VILLARD
2012-11-16  9:39           ` Jean-Christophe PLAGNIOL-VILLARD
2012-11-15  4:56 ` [PATCH 4/4] pinctrl: nomadik: " Axel Lin
2012-11-15  4:56   ` Axel Lin
2012-11-15 14:42   ` Linus Walleij
2012-11-15 14:42     ` Linus Walleij
2012-11-15 15:15     ` Lee Jones [this message]
2012-11-15 15:15       ` Lee Jones
2012-11-15  7:35 ` [PATCH 1/4] pinctrl: dove: " Thomas Petazzoni
2012-11-15  7:35   ` Thomas Petazzoni
2012-11-15 13:44   ` Axel Lin
2012-11-15 13:56     ` Thomas Petazzoni
2012-11-15 13:56       ` Thomas Petazzoni

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=20121115151541.GC14476@gmail.com \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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.