devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Chris Brandt <Chris.Brandt@renesas.com>
Cc: Jacopo Mondi <jacopo@jmondi.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH v4 1/2] pinctrl: Add RZ/A2 pin and gpio controller
Date: Thu, 15 Nov 2018 08:34:00 +0100	[thread overview]
Message-ID: <CAMuHMdVO9nh_zgxaBW9dmchfvxsVmLSEkm5_AcNrYE3Aw2EbRA@mail.gmail.com> (raw)
In-Reply-To: <OSAPR01MB155328061E423C6DD4504D828AC30@OSAPR01MB1553.jpnprd01.prod.outlook.com>

Hi Chris,

On Thu, Nov 15, 2018 at 12:41 AM Chris Brandt <Chris.Brandt@renesas.com> wrote:
> > > +   gpio_range.id = of_args.args[0];
> >
> > Do you think of_args need to be validated?
> > As I understand them, id and pin_base are fixed at 0, while the pin
> > number depends on the soc version/revision.
> >
> > Now I wonder if you would need a gpio-ranges property at all, but
> > that's fine, it doesn't hurt...
>
> My idea was that if another RZ/A2 with a different package size is
> created, or even a RZ/A3 with the same pin controller, nothing in the driver
> will have to change because the gpio-ranges is passed in and will tell
> you how many ports you have.
>
> As for validating the values, the only thing I can really check is that:
>   of_args.args[2] == RZA2_NPINS
>
> Of course, now that I say that, I realize that if/when it does come time
> to expand this driver beyond the 1 SOC that exists today, I will have
> to stop using that hard coded RZA2_NPINS value...but I'll deal with that
> when the time comes.

Not that there is an inherent danger in taking of_args.args[2] without
validation to support future SoCs without driver changes.
port_names[] is a fixed size array, so an SoC with more pins will
cause memory access beyond the end of the array. Possibly there are
other locations that need to be changed.

So IMHO it's better to have explicit support for different SoCs using
different compatible values, so you can store the number of pins in
of_device_id.data, and validate against that.

> > > +   ret = rza2_pinctrl_register(priv);
> > > +   if (ret)
> > > +           return ret;
> > > +
> > > +   pr_info("RZ/A2 pin controller registered\n");
> > nit: dev_info
>
> Actually, I changed it to this to anticipate the day when more than one
> SOC is supported:
>
>         dev_info(&pdev->dev, "Registered ports P0 - P%c\n",
>                  port_names[priv->desc.npins / RZA2_PINS_PER_PORT - 1]);

See, if npins becomes larger, you'll overflow port_names[].

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2018-11-15  7:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 18:27 [PATCH v4 0/2] pinctrl: Add RZ/A2 pin and gpio driver Chris Brandt
2018-11-07 18:27 ` [PATCH v4 1/2] pinctrl: Add RZ/A2 pin and gpio controller Chris Brandt
2018-11-12 18:58   ` Geert Uytterhoeven
2018-11-13 18:43     ` Chris Brandt
2018-11-13 19:00       ` Geert Uytterhoeven
2018-11-13 19:26         ` Chris Brandt
2018-11-13 22:18           ` Geert Uytterhoeven
2018-11-14 18:35             ` Chris Brandt
2018-11-13 19:57   ` jacopo mondi
2018-11-14 23:41     ` Chris Brandt
2018-11-15  7:34       ` Geert Uytterhoeven [this message]
2018-11-15 12:18         ` Chris Brandt
2018-11-07 18:27 ` [PATCH v4 2/2] dt-bindings: pinctrl: Add RZ/A2 pinctrl and GPIO Chris Brandt
2018-11-12 16:06   ` Geert Uytterhoeven
2018-11-13 16:38     ` Chris Brandt
2018-11-13 17:28       ` Geert Uytterhoeven
2018-11-13 17:58         ` Chris Brandt
2018-11-19 13:21         ` Linus Walleij
2018-11-19 13:42           ` Geert Uytterhoeven
2018-11-13 19:15   ` jacopo mondi
2018-11-13 19:33     ` Chris Brandt

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=CAMuHMdVO9nh_zgxaBW9dmchfvxsVmLSEkm5_AcNrYE3Aw2EbRA@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=Chris.Brandt@renesas.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=jacopo@jmondi.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).