RE: [PATCH] phy: renesas: phy-rcar-gen2: Fix the array off by one warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Geert, 

Thanks for the feedback.

> Subject: Re: [PATCH] phy: renesas: phy-rcar-gen2: Fix the array off by one
> warning
> 
> Hi Biju,
> 
> On Wed, May 15, 2019 at 3:50 PM Biju Das <biju.das@xxxxxxxxxxxxxx>
> 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@xxxxxxxxxx>
> > Signed-off-by: Biju Das <biju.das@xxxxxxxxxxxxxx>
> 
> Thanks for your patch!
> 
> Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> 
> While your patch is correct (to the best of my knowledge), I think the code
> can be made more maintainable by using ARRAY_SIZE().

Ok. I will send V2.

> > --- 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)
OK.

> >  };
> >
> >  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)
OK.

> >  };
> >
> >  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)

OK.
> >  };
> >
> >  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
OK.

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

Regards,
Biju




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux