From: plagnioj@jcrosoft•com (Jean-Christophe PLAGNIOL-VILLARD)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH RESEND 3/4] pinctrl: at91: Prevent NULL dereference if of_match_device returns NULL
Date: Fri, 16 Nov 2012 10:39:33 +0100 [thread overview]
Message-ID: <20121116093933.GE4398@game.jcrosoft.org> (raw)
In-Reply-To: <50A5FB17.1050208@atmel.com>
On 09:36 Fri 16 Nov , Nicolas Ferre wrote:
> On 11/15/2012 11:00 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > On 12:58 Thu 15 Nov , Axel Lin wrote:
> >> of_match_device() may return NULL.
> > this is not possible on at91
> >
> > and I do a oups here as if we have a NULL pointer which means the driver is
> > wrong
>
> Well, okay, but it does not prevent from adding a supplementary check to
> mimic every other pinctrl driver and use a common return path to the
> of_match_device() function.
>
> So I am not completely against this patch (that I why I added my Acked-by).
here it's a silent warning a oops it clear we have a bug
Best Regards,
J.
>
>
> >> Signed-off-by: Axel Lin <axel.lin@ingics•com>
> >> ---
> >> This resend CC Jean-Christophe.
> >>
> >> drivers/pinctrl/pinctrl-at91.c | 17 +++++++++++++----
> >> 1 file changed, 13 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
> >> index 8490a55..32006c8 100644
> >> --- a/drivers/pinctrl/pinctrl-at91.c
> >> +++ b/drivers/pinctrl/pinctrl-at91.c
> >> @@ -829,13 +829,18 @@ static int __devinit at91_pinctrl_probe_dt(struct platform_device *pdev,
> >> uint32_t *tmp;
> >> struct device_node *np = pdev->dev.of_node;
> >> struct device_node *child;
> >> + const struct of_device_id *match;
> >>
> >> if (!np)
> >> return -ENODEV;
> >>
> >> + match = of_match_device(at91_pinctrl_of_match, &pdev->dev)->data;
> >> + if (!match)
> >> + return -ENODEV;
> >> +
> >> info->dev = &pdev->dev;
> >> - info->ops = (struct at91_pinctrl_mux_ops*)
> >> - of_match_device(at91_pinctrl_of_match, &pdev->dev)->data;
> >> + info->ops = (struct at91_pinctrl_mux_ops *) match->data;
> >> +
> >> at91_pinctrl_child_count(info, np);
> >>
> >> if (info->nbanks < 1) {
> >> @@ -1359,6 +1364,7 @@ static struct of_device_id at91_gpio_of_match[] __devinitdata = {
> >> static int __devinit at91_gpio_probe(struct platform_device *pdev)
> >> {
> >> struct device_node *np = pdev->dev.of_node;
> >> + const struct of_device_id *match;
> >> struct resource *res;
> >> struct at91_gpio_chip *at91_chip = NULL;
> >> struct gpio_chip *chip;
> >> @@ -1399,8 +1405,11 @@ static int __devinit at91_gpio_probe(struct platform_device *pdev)
> >> goto err;
> >> }
> >>
> >> - at91_chip->ops = (struct at91_pinctrl_mux_ops*)
> >> - of_match_device(at91_gpio_of_match, &pdev->dev)->data;
> >> + match = of_match_device(at91_gpio_of_match, &pdev->dev);
> >> + if (!match)
> >> + return -ENODEV;
> >> +
> >> + at91_chip->ops = (struct at91_pinctrl_mux_ops *) match->data;
> >> at91_chip->pioc_virq = irq;
> >> at91_chip->pioc_idx = alias_idx;
> >>
> >> --
> >> 1.7.9.5
> >>
> >>
> >>
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
> >
>
>
> --
> Nicolas Ferre
next prev parent reply other threads:[~2012-11-16 9:39 UTC|newest]
Thread overview: 15+ 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:52 ` [PATCH 2/4] pinctrl: kirkwood: " Axel Lin
2012-11-15 19:18 ` Thomas Petazzoni
2012-11-15 4:54 ` [PATCH 3/4] pinctrl: at91: " Axel Lin
2012-11-15 4:58 ` [PATCH RESEND " Axel Lin
2012-11-15 8:23 ` Nicolas Ferre
2012-11-15 10:00 ` Jean-Christophe PLAGNIOL-VILLARD
2012-11-16 8:36 ` Nicolas Ferre
2012-11-16 9:39 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-11-15 4:56 ` [PATCH 4/4] pinctrl: nomadik: " Axel Lin
2012-11-15 14:42 ` Linus Walleij
2012-11-15 15:15 ` Lee Jones
2012-11-15 7:35 ` [PATCH 1/4] pinctrl: dove: " Thomas Petazzoni
2012-11-15 13:44 ` Axel Lin
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=20121116093933.GE4398@game.jcrosoft.org \
--to=plagnioj@jcrosoft$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox