Linux-Renesas-SoC Archive on lore.kernel.org
 help / color / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Biju Das <biju.das@bp.renesas.com>
Cc: Kishon Vijay Abraham I <kishon@ti.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Simon Horman <horms+renesas@verge.net.au>,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
	Simon Horman <horms@verge.net.au>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Chris Paterson <Chris.Paterson2@renesas.com>,
	Fabrizio Castro <fabrizio.castro@bp.renesas.com>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH] phy: renesas: phy-rcar-gen2: Fix the array off by one warning
Date: Thu, 16 May 2019 14:40:18 +0200
Message-ID: <CAMuHMdUnMhDyEoFDs05WKU=0PtV2FmAxuGWFhf7ekxfK=Y5gSg@mail.gmail.com> (raw)
In-Reply-To: <1557927786-29557-1-git-send-email-biju.das@bp.renesas.com>

Hi Biju,

On Wed, May 15, 2019 at 3:50 PM Biju Das <biju.das@bp.renesas.com> wrote:
> Fix the below smatch warning by adding variable check rather than the
> hardcoded value.
> warn: array off by one? 'data->select_value[channel_num]'
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Biju Das <biju.das@bp.renesas.com>

Thanks for your patch!

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

While your patch is correct (to the best of my knowledge), I think the
code can be made more maintainable by using ARRAY_SIZE().

> --- a/drivers/phy/renesas/phy-rcar-gen2.c
> +++ b/drivers/phy/renesas/phy-rcar-gen2.c
> @@ -71,6 +71,7 @@ struct rcar_gen2_phy_driver {
>  struct rcar_gen2_phy_data {
>         const struct phy_ops *gen2_phy_ops;
>         const u32 (*select_value)[PHYS_PER_CHANNEL];
> +       const u32 last_channel;

num_channels? (which is one more than last_channel)

>  };
>
>  static int rcar_gen2_phy_init(struct phy *p)
> @@ -271,11 +272,13 @@ static const u32 usb20_select_value[][PHYS_PER_CHANNEL] = {
>  static const struct rcar_gen2_phy_data rcar_gen2_usb_phy_data = {
>         .gen2_phy_ops = &rcar_gen2_phy_ops,
>         .select_value = pci_select_value,
> +       .last_channel = 2,

.num_channels = ARRAY_SIZE(pci_select_value)

>  };
>
>  static const struct rcar_gen2_phy_data rz_g1c_usb_phy_data = {
>         .gen2_phy_ops = &rz_g1c_phy_ops,
>         .select_value = usb20_select_value,
> +       .last_channel = 0,

.num_channels = ARRAY_SIZE(usb20_select_value)

>  };
>
>  static const struct of_device_id rcar_gen2_phy_match_table[] = {
> @@ -389,7 +392,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
>                 channel->selected_phy = -1;
>
>                 error = of_property_read_u32(np, "reg", &channel_num);
> -               if (error || channel_num > 2) {
> +               if (error || channel_num > data->last_channel) {

>= data->num_channels

>                         dev_err(dev, "Invalid \"reg\" property\n");
>                         return error;
>                 }

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

  parent reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 13:43 Biju Das
2019-05-16 11:13 ` Simon Horman
2019-05-16 12:16 ` Wolfram Sang
2019-05-16 12:32   ` Biju Das
2019-05-16 12:34   ` Geert Uytterhoeven
2019-05-16 13:25     ` Wolfram Sang
2019-05-16 12:40 ` Geert Uytterhoeven [this message]
2019-05-16 13:03   ` Biju Das

Reply instructions:

You may reply publically 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='CAMuHMdUnMhDyEoFDs05WKU=0PtV2FmAxuGWFhf7ekxfK=Y5gSg@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=Chris.Paterson2@renesas.com \
    --cc=biju.das@bp.renesas.com \
    --cc=dan.carpenter@oracle.com \
    --cc=fabrizio.castro@bp.renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=horms+renesas@verge.net.au \
    --cc=horms@verge.net.au \
    --cc=kishon@ti.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=yoshihiro.shimoda.uh@renesas.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

Linux-Renesas-SoC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-renesas-soc/0 linux-renesas-soc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-renesas-soc linux-renesas-soc/ https://lore.kernel.org/linux-renesas-soc \
		linux-renesas-soc@vger.kernel.org linux-renesas-soc@archiver.kernel.org
	public-inbox-index linux-renesas-soc


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-renesas-soc


AGPL code for this site: git clone https://public-inbox.org/ public-inbox