phy: renesas: phy-rcar-gen2: Fix the array off by one warning
authorBiju Das <biju.das@bp.renesas.com>
Wed, 9 Oct 2019 16:12:49 +0000 (17:12 +0100)
committerKishon Vijay Abraham I <kishon@ti.com>
Thu, 31 Oct 2019 11:24:01 +0000 (16:54 +0530)
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>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Ulrich Hecht <uli+renesas@fpond.eu>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
drivers/phy/renesas/phy-rcar-gen2.c

index 2926e49373017ba972fb162a4d88b34fa61d5010..2e279ac0fa4d68b624a2cf0a0db547165a9e1d86 100644 (file)
@@ -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 num_channels;
 };
 
 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,
+       .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,
+       .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->num_channels) {
                        dev_err(dev, "Invalid \"reg\" property\n");
                        of_node_put(np);
                        return error;