Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: renesas: phy-rcar-gen2: Fix the array off by one warning

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>

authored by

Biju Das and committed by
Kishon Vijay Abraham I
c9baab38 82b5d164

+4 -1
+4 -1
drivers/phy/renesas/phy-rcar-gen2.c
··· 71 71 struct rcar_gen2_phy_data { 72 72 const struct phy_ops *gen2_phy_ops; 73 73 const u32 (*select_value)[PHYS_PER_CHANNEL]; 74 + const u32 num_channels; 74 75 }; 75 76 76 77 static int rcar_gen2_phy_init(struct phy *p) ··· 272 271 static const struct rcar_gen2_phy_data rcar_gen2_usb_phy_data = { 273 272 .gen2_phy_ops = &rcar_gen2_phy_ops, 274 273 .select_value = pci_select_value, 274 + .num_channels = ARRAY_SIZE(pci_select_value), 275 275 }; 276 276 277 277 static const struct rcar_gen2_phy_data rz_g1c_usb_phy_data = { 278 278 .gen2_phy_ops = &rz_g1c_phy_ops, 279 279 .select_value = usb20_select_value, 280 + .num_channels = ARRAY_SIZE(usb20_select_value), 280 281 }; 281 282 282 283 static const struct of_device_id rcar_gen2_phy_match_table[] = { ··· 392 389 channel->selected_phy = -1; 393 390 394 391 error = of_property_read_u32(np, "reg", &channel_num); 395 - if (error || channel_num > 2) { 392 + if (error || channel_num >= data->num_channels) { 396 393 dev_err(dev, "Invalid \"reg\" property\n"); 397 394 of_node_put(np); 398 395 return error;